重定向
例:http://localhost:8080/Test/MyJsp.jsp
请求URL:http://localhost:8080/Test/
相对路径,无”/”(容器会相对于原先的请求URL建立完整的URL), 如请求上述URL
Response.sendRedirect(“test.jsp”);
绝对路径,有”/”(容器会相对于Web应用本身建立完整的URL,如
response.sendRedirect("/Test/MyJsp.jsp");
ps:不能写在响应之后再调用sendRedirect()
PrintWriter writer =response.getWriter();
writer.write("hh");
writer.flush();
response.sendRedirect("/Test/MyJsp.jsp");
请求分派(页面转发) (地址栏没有变化)
这样页面跳转后请求仍是页面转发前的那个请求(转发时可对请求进行修改)
RequestDispatcherview = request.getRequestDispatcher(“MyJsp.jsp”);
View.forward(request,response);