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
- public class QADHandlerExceptionResolver implements HandlerExceptionResolver{
- private static Logger logger = Logger.getLogger(QADHandlerExceptionResolver.class);
- @Override
- public ModelAndView resolveException(HttpServletRequest request,
- HttpServletResponse response, Object handler, Exception ex) {
- logger.error( "Catch Exception: " ,ex); //Record the exception information that missed the net in the log
- Object ex=request.getAttribute("ex");
- if(ex instanceof myException) {
- if(myException.getCode=="1"){
- return new ModelAndView("login");
- }
- }
- return new ModelAndView("login");
- }
- }