配置过滤器:
public class AccessFilter implements Filter{
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse res=(HttpServletResponse)response;
HttpServletRequest req=(HttpServletRequest)request;
String path=req.getRequestURI();
System.out.println(path);
if(path.endsWith("login.html") || path.endsWith("register.html")) {
chain.doFilter(request, response);
return;
}
HttpSession session =req.getSession();
Object id=session.getAttribute("id");
if(id==null) {
//System.out.println("用户没有登录");
String contextPath=req.getContextPath();
//System.out.println("contextpath:"+contextPath);
res.sendRedirect(contextPath+"/login.html");
return;
}
chain.doFilter(reques