Jsp重定向
1.html中的<a href=url></a>标签
2.重定向 response.sendRedirect("NewFile.jsp");
3.请求转发request.getRequestDispatcher("/WEB-INF/Views/NewFile2.jsp").forward(request, response);4.<form action="rouse3.jsp" name="rou" id="rou" method="post" >
5.function name(){
window.location.href="url";
}request.getRequestDispatcher()与response.sendRedirect()区别
1.request.getRequestDispatcher()是请求转发,前后页面共享一个request ;
response.sendRedirect()是重新定向,前后页面不是一个request。2、运用forward方法只能重定向到同一个Web应用程序中的一个资源。而sendRedirect方法可以转向到本Web应用之外的页面和网站,转向的速度相对要慢。
表单form的action="/uu";sendRedirect("/uu");表示相对于服务器根路径。如http://localhost:8080/Test应用(则提交至http://localhost:8080/uu);
Forward代码中的"/uu"则代表相对与WEB应用的路径。如http://localhost:8080/Test应用(则提交至http://localhost:8080/Test/uu);
3、sendRedirect方法,地址栏显示的地址是所转向到的Servlet或者JSP的地址。
forward方法,地址栏显示的地址是所转向前原Servlet的地址。
4、sendRedirect方法,重新定向, 前后页面 不共用一个request,不可以读取转向前request对象通过setAttribute()方法所设定的属性值。
forward方法,为转发,前后页面共用一个request,通过request的getAttribute()方法可以读取转向前request对象通 过 setAttribute ()方法所设定的属性值。