public void doFilter(ServletRequest arg0,ServletResponse arg1,FilterChain chain) throws IOException, ServletException{
HttpServletRequest req=(HttpServletRequest)arg0;
HttpServletResponse resp=(HttpServletResponse)arg1;
Object user=req.getSession().getAttribute("user");
String uri=req.getRequestURI();
String url=req.getRequestURL().toString();
System.out.println("SecurityFilter uei=========="+uri);
System.out.println("SecurityFilter url++++++++++"+url);
// 用户想要进入登录页面和用户需要提交的登录数据
if("/test/hello.jsp".equals(uri)||"/test/my".equals(uri)){
// 用户在提交登录的信息
chain.doFilter(arg0, arg1);
}else if(user==null){
// 没有登录
resp.sendRedirect("hello.jsp");
}else{
// 登录了系统,可以访问
chain.doFilter(arg0, arg1);
}
}
转载于:https://www.cnblogs.com/xiaoqisfzh/p/5959022.html