最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Method to open another jsp page in Javascript - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Jul 27, 2012 at 20:02 user1506919user1506919 2,6075 gold badges22 silver badges15 bronze badges 1
  • +1 - Great question!! You provided enough information to help see what you're trying to acplish. Thank you for putting effort into your question. – jamesmortensen Commented Jul 27, 2012 at 20:08
Add a ment  | 

3 Answers 3

Reset to default 7

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.

this should open new tab with GeneralInfo.jsp when you click on the General Info button..

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

you can use this method,

 <input type="button" value="General Info" name="INfoPage"
        onclick="document.forms[0].action = 'infoPage.jsp';" />

or the easy way is,

<a href="InfoPage.jsp">General Info</a>
发布评论

评论列表(0)

  1. 暂无评论