zoukankan      html  css  js  c++  java
  • 拦截非法登录

    仅需一个类

    @WebFilter(urlPatterns = {"/**"})
    public class myfilter implements Filter {
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
    
        }
    
        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException, IOException {
            HttpServletRequest httpServletRequest=(HttpServletRequest) servletRequest;
            System.out.println(httpServletRequest.getRequestURI());
            if(httpServletRequest.getRequestURI().equals("/stu/login")){
                filterChain.doFilter(servletRequest,servletResponse);
                System.out.println("合法请求");
            }
            Object user = httpServletRequest.getSession().getAttribute("user");
            if(user==null){
                System.out.println("非法请求");
                httpServletRequest.getRequestDispatcher("/jsp/login.jsp").forward(servletRequest,servletResponse);
            }else{
                filterChain.doFilter(servletRequest,servletResponse);
            }
        }
    
        @Override
        public void destroy() {
    
        }
    }
  • 相关阅读:
    noip不知道哪年 货车运输
    bzoj1002轮状病毒
    bzoj1001狼抓兔子
    20171002模拟赛
    20171001模拟赛
    异常
    springmvc-servlet.xml 第二种选择
    springmvc入门
    springmvc-servlet.xml(springmvc-servlet.xml 配置 增强配置)
    777
  • 原文地址:https://www.cnblogs.com/whtt/p/11868152.html
Copyright © 2011-2022 走看看