zoukankan      html  css  js  c++  java
  • jsp实现页面跳转的几种方式

    一,  使用href超链接标记              (客户端跳转)

    二,  提交表单                            (客户端跳转)

        <form name="form" method="post" action="page2.jsp">

                  <input type="submit" value="跳转1">

              </form>

    三,  Javascrip事件       (客户端跳转)

        <input type="button" value="跳转2" onclick="next()">

            <script type="text/javascript">

                  function next(){

                      window.location = "page2.jsp";

                  }

             </script>

    四,  使用response对象     (客户端跳转)(重定向)

        <%  response.sendRedirect("page2.jsp"); %>         //sendRedirect()可以带参数传递,后面应该紧跟一句return

        <%   response.setHeader("Refresh", "1;url=page2.jsp"); %>  //1秒后,刷新,并跳到,page2.jsp页面

    五,  使用forward动作标记   (服务器端跳转)(转发)

        jsp自带的forword标签来实现跳转    <jsp:forward page="page2.jsp" /> 

    六,   使用RequestDispatcher类     (服务器端跳转)(转发) 

        <% request.getRequestDispatcher("page2.jsp").forward(request, response);%>  

    response重定向和forward跳转和RequestDispatcher的区别

    (1) response重定向

        执行完页面的所有代码,再跳转到目标页面。
        跳转到目标页面后,浏览器地址栏中的URL会改变。
        在浏览器端重定向。
        可以跳转到其它服务器上的页面,response.sendRedirect(“http://www.baidu.com”)

    (2) forward跳转

        forward动作标记之后的代码,不再执行,直接跳转到目标页面。
        跳转到目标页面后,浏览器地址栏中的URL不会改变。
        在服务器端重定向。
        无法跳转到其它服务器上的页面。

        指定目标页面时,既可以使用绝对路径,也可以使用相对路径。

    (3) RequestDispatcher跳转

        执行完所有代码,包括RequestDispatcher之后的所有代码,再跳转到目标页面。
        跳转到目标页面后,浏览器地址栏中的URL不会改变。
        在服务器端重定向。
        无法跳转到其它服务器上的页面。

        指定目标页面时,只能使用绝对路径。

          

     

  • 相关阅读:
    JAVA微信公众号网页开发——获取公众号关注的所有用户
    删除mysl
    sql语言(mysql)
    mycat读写分离
    mysql双主双从技术
    实用的10个日志处理案例
    ansible基本操作
    MySQL改密
    mysql源码包安装
    ftp搭建mysql服务器
  • 原文地址:https://www.cnblogs.com/liuqu/p/8668908.html
Copyright © 2011-2022 走看看