项目中登录的路径:/user/login.action 现在要多登录过滤,如果没用户登录就跳到登录页面,我的filter方法如下:public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpSession session = ((HttpServletRequest) request).getSession();
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpRes = (HttpServletResponse) response;
String url = httpReq.getServletPath();
String path = httpReq.getContextPath();
//把login.jsp排除掉
if ((url.startsWith("/")&& !url.startsWith("/user/login")&& !url.startsWith("/login.jsp"))) {// 若访问后台资源
User user = (User) session.getAttribute("user");
if (user == null) {// 转入管理员登陆页面
httpRes.sendRedirect(path + "/login.jsp");
return;
}
}
chain.doFilter(request, response);
},现在直接输入登录的long.action是报错的,因为我把login.action没给过滤,如果不加")&& !url.startsWith("/user/login")这句的话,他就会过滤这个login.action,跑到登录页面,当我输入登录信息,点击登录时,它还会走这个过滤方法,求解决方法