1.httpRespoinse.sendRedirect("");
2.request.getRequestDispatcher( "url ").forward(request,response);
3.FilterConfig.getServletContext().getRequestDispatcher("/adminUserAction!toLogin.action").forward(request, response)
第一种方式对配置没有要求,基本上什么情况下都可以用.
servletContext获取的requestDispatcher据说可以访问其他web应用.
另外,如果要转发到struts2 action,struts2需要配置:
<filter-mapping>
<filter-name>permissionServlet</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
2.request.getRequestDispatcher( "url ").forward(request,response);
3.FilterConfig.getServletContext().getRequestDispatcher("/adminUserAction!toLogin.action").forward(request, response)
第一种方式对配置没有要求,基本上什么情况下都可以用.
Servlet可通过两种方式得到RequestDispatcher对象:
调用ServletContext的getRequestDispatcher(String path)方法,path参数指定目标组件的路径。
调用ServletRequest的getRequestDispatcher(String path)方法
以上两种方式的区别在于,前者的path参数必须是绝对路径,而后者的path参数可以是绝对路径,也可以是相对路径。所谓绝对路径,就是指以符号"/"开头的路径,"/"表示当前web应用的URL入口。
另外,如果要转发到struts2 action,struts2需要配置: