思路,先登陆后,将登陆信息存储在session中,然后通过拦截器,对系统中的页面和资源进行访问拦截,同时对于登陆本身相关的页面和资源不拦截。

 

实现方法:

/** 
         
 
         
 
            
          * 登陆拦截器. 
         
 
         
 
            
          * 
         
 
         
 
            
          * @author leizhimin 2014/6/26 16:08 
         
 
         
 
            
          */ 
         
 
         
 
          public  
          class  
          LoginInterceptor  
          extends  
          HandlerInterceptorAdapter { 
         
 
         
 
               
          private  
          static  
          final  
          String[] IGNORE_URI = { 
          "/login.jsp" 
          ,  
          "/Login/" 
          , 
          "backui/" 
          , 
          "frontui/" 
          }; 
         
 
         

             
         
 
         
 
               
          @Override 
         
 
         
 
               
          public  
          boolean  
          preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  
          throws  
          Exception { 
         
 
         
 
                   
          boolean  
          flag =  
          false 
          ; 
         
 
         
 
                   
          String url = request.getRequestURL().toString(); 
         
 
         
 
                   
          System.out.println( 
          ">>>: "  
          + url); 
         
 
         
 
                   
          for  
          (String s : IGNORE_URI) { 
         
 
         
 
                       
          if  
          (url.contains(s)) { 
         
 
         
 
                           
          flag =  
          true 
          ; 
         
 
         
 
                           
          break 
          ; 
         
 
         
 
                       
          } 
         
 
         
 
                   
          } 
         
 
         
 
                   
          if  
          (!flag) { 
         
 
         
 
                       
          T_supplier_user user = LoginController.getLoginUser(request); 
         
 
         
 
                       
          if  
          (user !=  
          null 
          ) flag =  
          true 
          ; 
         
 
         
 
                   
          } 
         
 
         
 
                   
          return  
          flag; 
         
 
         
 
               
          } 
         
 
         

             
         
 
         
 
               
          @Override 
         
 
         
 
               
          public  
          void  
          postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)  
          throws  
          Exception { 
         
 
         
 
                   
          super 
          .postHandle(request, response, handler, modelAndView); 
         
 
         
 
               
          } 
         
 
         
 
          }

 


<          mvc:interceptors          >         


                    <          mvc:interceptor          >         


                    <          mvc:mapping           path          =          "/**"          />         


                    <          bean           id          =          "loginInterceptor"           class          =          "net.xiucheren.web.interceptor.LoginInterceptor"          />         


                    </          mvc:interceptor          >         


                    </          mvc:interceptors          >