• 添加filter过滤器 (静态资源放行)


    里面加了没有登录的时候,操作时就需要登录

    package com.quicksure.mobile.filter;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import com.quicksure.mobile.entity.Userinfor;
    
    public class LudiMobileFilter implements Filter {
        public void destroy() {
            // TODO Auto-generated method stub
        }
    
        public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws IOException, ServletException {         
            HttpServletRequest req = (HttpServletRequest) request; 
            HttpServletResponse resp = (HttpServletResponse) response; 
            HttpSession session = req.getSession();
            String path = req.getContextPath();
            String url = req.getRequestURI();
            Userinfor user = (Userinfor) session.getAttribute("loginUser");
            String conString = req.getHeader("REFERER"); //获取父url,这里当浏览器url选中,敲enter键时,conString就会为空了
            
            if("".equals(conString) || null==conString){                     
                String servletPath = req.getServletPath();
                if (servletPath.indexOf("index") > 0 || servletPath.indexOf("LoginUser") > 0||servletPath.indexOf("MP_verify_PPlSQIplLY8fbefx.txt")>0) {
                    chain.doFilter(request, response);
                } else { // 当前请求url
                    resp.sendRedirect(path + "/views/quicksure/jsp/index.jsp");
                    session.removeAttribute("loginUser");
                } 
            }else{
                if(url.endsWith(".css")||url.endsWith(".js")||url.endsWith(".jpg")
                    ||url.endsWith(".gif")||url.endsWith(".png")||url.endsWith("/index.jsp")
                    ||url.endsWith("/LoginUser.jsp")||url.endsWith("getDptCode.do")
                    ||url.endsWith("checkPhoneCode.do")||url.endsWith("userLogin.do")
                    ||url.endsWith("phoneCheck.do")||url.endsWith("/registUser.jsp")||url.endsWith("registUser.do")
                    ||url.endsWith("resetPassword.do")||url.endsWith("/resetPassword.jsp")||url.endsWith("goPaymentSucessPage.do")){
                    chain.doFilter(request, response);
                }else{
                    if (user == null ) {
                        // 跳转到登陆页面
                        req.getRequestDispatcher("/views/quicksure/jsp/LoginUser.jsp").forward(request, response);
                        //request.getRequestDispatcher().forward(request, response);
                        //resp.sendRedirect(path+"/views/quicksure/jsp/LoginUser.jsp");
                    } else {
                        // 已经登陆,继续此次请求
                        chain.doFilter(request, response);
                    }
                }
            }         
        }
    
        public void init(FilterConfig arg0) throws ServletException {
            // TODO Auto-generated method stub 
        }
    
    }
  • 相关阅读:
    Linux文件系统
    Linux用户和用户管理
    Linux磁盘管理
    vi编辑器
    Linux常用命令
    Linux进程管理
    servlet运行过程
    http的get和post方法的区别
    千元机小荐
    JavaScript 正则表达式(Reg Exp)
  • 原文地址:https://www.cnblogs.com/ldbangel/p/6094573.html
Copyright © 2020-2023  润新知