Javaweb
未登录被filter过滤,过滤后重定向到登录页面,然后登录后就不放行被过滤的页面了该怎么办
```java
package filter;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
public class LoginCheckFilter implements Filter {
private String excludedPages;
private String[] excludedPageArray;
@Override
public void init(FilterConfig config) throws ServletException {
excludedPages = config.getInitParameter("excludedPages");
if (null != excludedPages && excludedPages.length() > 0) {
excludedPageArray = excludedPages.split(",");
}
return;
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
boolean isExcludedPage = false;
HttpSession session = ((HttpServletRequest) req).getSession();
Object user = session.getAttribute("user");
System.out.println("user"+user);
// 获取不过滤的列表
for (String page : excludedPageArray) {
if (((HttpServletRequest) req).getServletPath().equals(page)) {
isExcludedPage = true;
break;
}
}
if (isExcludedPage) { //如果有不过滤的页面,放行
chain.doFilter(req, resp);
} else {
if (user != null){
chain.doFilter(req,resp);
}else {
((HttpServletRequest)req).getRequestDispatcher("/first.jsp").forward(req,resp);
}
}
}
@Override
public void destroy() {
}
}
```