在STRUTS2的FILTER之前 比如StrutsPrepareAndExecuteFilter之前放一个FILTER
可以进行reponse.sendRedirect操作
或者request.getRequestDispatcher().forward操作
如果forward以后要继续经过struts2的FILTER 那么STRUTS2的FILTER要这样配置
<filter-mapping>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
这个是SERVLET2.4的新的特性 意思是让这个FILTER也可以接受经过FORWARD转发来的请求。
下面是这个例子
public class SwpFilter extends StrutsPrepareAndExecuteFilter {
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse reponse = (HttpServletResponse) res;
//在这里进行URLREWRITE的操作
if (request.getRequestURI().equals("/aa")) {
request.getRequestDispatcher("swp/getResource?type=page&id=609&edit=true").forward(req,
res);
return;
}
if (request.getServletPath().startsWith("/fckeditor")) {
super.doFilter(req, res, chain);
} else if (request.getServletPath().equals("/manager/")) {
reponse.sendRedirect(request.getRequestURI() + "manager.jsp");
} else if (request.getServletPath().equals("/login")) {
reponse.sendRedirect("manager/login.jsp");
} else if (request.getServletPath().equals("/login/")) {
reponse.sendRedirect("../manager/login.jsp");
} else {
super.doFilter(req, res, chain);// 调用父类的方法
}
}
}