Spring mvc does not log in to intercept the jump landing page

When intercepting, you will directly jump to login.jsp without logging in 

In the previous project, two methods were used

(1)

ajax asynchronous login

If not logged in, return a restfulMessage (custom return class) and define a code in it 

If the interceptor finds that it is not logged in, it will return this and then judge the code inside and then window.location.href="login.jsp"

 

(2)

This is what I have seen recently. I tested the following and found that it is not bad 

That is, there is an abstract class HandlerExceptionResolver in the servlet

 

When intercepting, if you find that you are not logged in, throw this exception directly

The following method catches this exception

 

  1. public class QADHandlerExceptionResolver implements HandlerExceptionResolver{  
  2.     private static Logger logger = Logger.getLogger(QADHandlerExceptionResolver.class);  
  3.     @Override  
  4.     public ModelAndView resolveException(HttpServletRequest request,  
  5.             HttpServletResponse response, Object handler, Exception ex) {  
  6.         logger.error( "Catch Exception: " ,ex); //Record the exception information that missed the net in the log  
  7.        Object ex=request.getAttribute("ex");
  8.         if(ex instanceof myException) {
  9.              if(myException.getCode=="1"){
  10.                return new ModelAndView("login");  
  11. }
  12. }
  13.         return new ModelAndView("login");  
  14.     }  
  15.   
  16. }

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326158793&siteId=291194637