public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request=(HttpServletRequest) arg0;//获取request
String path = request.getRequestURI().toString() ;//获取提交 action,jsp等地址
String[] pa=path.split("/");//截取地址/Jquer/userlogin.jsp
path=pa[pa.length-1]; //取出最后一个:比如 userlogin.jsp
if(path.equals("logins.jsp")||path.equals("jspyanzheng.jsp")||path.equals("usersAction.action")){
//如果是登录页面,登录页面的验证码,还有点击登录按钮时 所要跳转的action 放行
arg2.doFilter(arg0, arg1);//放行
}else{
HttpSession session= request.getSession();
Users users=(Users) session.getAttribute("users");
if(users!=null){
arg2.doFilter(arg0, arg1);//放行
}else{
//如果session 不存在 就跳转到登录页面
HttpServletResponse response=(HttpServletResponse) arg1;
PrintWriter out= arg1.getWriter();
session.setAttribute("denglunihao","hahahha"); //存入后 为了能在 登录页面弹框
response.sendRedirect("logins.jsp");
}
}
}