Servlet跳转
页面跳转的两种形式
1. 客户端跳转(页面改变,执行完跳转,无法传递reqeust属性)
2. 服务器端跳转(页面不改变,立刻无条件跳转,可以传递reqeust属性)
客户端跳转(重定向)
- 可以传递session,无法传递request属性
response.sendRedirect("show.jsp");
服务器端跳转
JSP页面中进行服务器跳转的2种方式
<jsp:forward page="" />
使用pageContext对象
pageContext.forward("");
通过Servlet实现服务器端跳转,必须依靠javax.servlet.RequestDispatcher接口
public RequestDispatcher getRequestDispatcher(String path)
req.getRequestDispatcher("/show.jsp").forward(req,resp)
99%情况下都使用服务器端跳转,且传递的属性范围都是reqeust属性范围。