在Servlet中如果要进行客户端跳转,直接使用HttpServletResponse接口的sendRedirect()方法即可。但需要注意的是,此跳转只能传递session范围的属性,而无法传递request范围的属性;
在Servlet中想要执行服务器端跳转,就必须依靠RequestDispatcher接口完成:
Public void forward(ServletRequest request, ServletResponse response)throws ServletException,IOException 页面跳转
Public void include(ServletRequest request,ServletResponse response)throws ServletException,IOException页面包含
使用RequestDispatcher接口的forward()方法即可完成跳转功能的实现,但是如果想要使用此接口还需要使用ServletRequest接口提供的getRequestDispatcher()方法进行实例化:
Public RequestDispatcher getRequestDispatcher(String path) 取得RequestDispatcher接口实例化。
例如:
RequestDispatcher rd=req.getRequestDispatcher();
浙公网安备 33010602011771号