感谢火龙果,认识你让我学到很多
以下代码为火龙果的过滤器片段
<servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*</url-pattern> </servlet-mapping>
这样配置不会造成死循环,也不用每次去form和action都加一次判断,一次配置就可以全部判断了
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpSession session = httpRequest.getSession();
if(session.getAttribute(ApplicationSource.USER) == null
&& !httpRequest.getRequestURI().endsWith("/login.vm") // 这些都是一些需要排除的页面
&& !httpRequest.getRequestURI().endsWith("/calendar/")
&& (httpRequest.getRequestURI().indexOf("/calendar/img") < 0)
&& (httpRequest.getRequestURI().indexOf("/calendar/resources") < 0)
&& (httpRequest.getRequestURI().indexOf("/calendar rvlet") < 0)
&& !httpRequest.getRequestURI().endsWith("/login.do")){
httpResponse.sendRedirect(httpRequest.getContextPath() + "/login.vm");
}
chain.doFilter(request, response);
黑色头发 http://heisetoufa.iteye.com
如果发现本文有误,欢迎批评指正