public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
System.out.println("IllegalVisitorFilter doFilter() is launched.");
HttpServletRequest request=(HttpServletRequest) req;
HttpServletResponse response=(HttpServletResponse) resp;
String url=request.getRequestURI();
String methodName=request.getParameter("method");
url=url+"_"+methodName;
System.out.println(url); // request路径中是否包含login字符串?目的是判断是否需要拦截? if(url.contains("login"))
{ chain.doFilter(request, response); return; }
System.out.println("**********************");
Object object = request.getSession().getAttribute("username");
if(object==null){
System.out.println("当前没有登录哦,退回登录界面!");
response.sendRedirect(request.getContextPath()+"/login.jsp"); }
else{
System.out.println(object.toString());
chain.doFilter(request, response); }
}
网友评论