Method to open another jsp page in Javascript

44,670

You could use window.location to redirect the user to the corresponding JSP pages; however, you'll need to make sure your paths in the code below match the actual paths to your JSP page as mapped by your servlet or based on the absolute path relative to the application.

   function goToInfo(){
       window.location = '/GeneralInfo.jsp';
   }

   function goToOther(){
       window.location = '/someOtherJSPPage.jsp';
   }

If you get 404 errors when trying to redirect to your JSP page, try turning up your logging level to ALL or DEBUG so that you can see the logs from the framework or Java container, these will hopefully show you the real file paths so that you can then adjust the URL to match the actual target location.

Share:
44,670
user1506919
Author by

user1506919

Updated on July 09, 2022

Comments

  • user1506919
    user1506919 almost 2 years

    I am trying to use buttons in an html/javascript program to redirect someone to another one of my pages. Basically, I created a .jsp page that gives the user some buttons to click. If the user clicks a button, it calls a method that is supposed to open a new .jsp page that I created under the same project. However, I have no clue how to do this as I am brand new to Javascript and HTML. I provided an example below:

    Sample Page

    <html>
    <title>Web Page</title>
    <body>
    
        <p>Please click a button to redirect you to the page you wish to go to.</p>
    
        <br>
    
        <form>
            <input type="button" id="idname" value = "General Info " onclick="goToInfo()"/><br>
        </form>
    
        <br>
    
        <form>
            <input type="button" id="idname" value = "Other Information" onclick="goToOther()"/><br>
        </form>
    
    
    
        <script type="text/javascript">
            function goToInfo(){
    
            }
    
            function goToOther(){
    
            }
    
            </script>
    </body>
    </html>
    

    *For example, I have another page in my NetBeans project that is called "GeneralInfo.jsp" and I want goToInfo() to be able to redirect the person to that page. Thank you for your help.