美文网首页
IllegalVistorFilter2018-07-09

IllegalVistorFilter2018-07-09

作者: hothome99 | 来源:发表于2018-07-09 18:15 被阅读0次

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); }

 }

相关文章

网友评论

      本文标题:IllegalVistorFilter2018-07-09

      本文链接:https://www.haomeiwen.com/subject/tnbtpftx.html