Home > Back-end >  Login to intercept
Login to intercept

Time:12-24

1, when login successful pass a session to store user object

The HttpSession session=requst. GetSession ();
Session. SetAttribute (Constant USER_IN_SESSION, user);


2, determine the user logged in, access to the session, if the session is empty, says the user is not logged on, intercept users to jump to the login screen, if true, indicates the user has logged in, to the user release

Public class UserInterceptor implements HandlerInterceptor {

@ Override
Public void afterCompletion (it arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
Throws the Exception {
//TODO Auto - generated method stub

}

@ Override
Public void postHandle (it arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
Throws the Exception {
//TODO Auto - generated method stub

}

@ Override
Public Boolean preHandle (it the req, HttpServletResponse resp, Object arg2) throws the Exception {
//get the session
Object the Object=the req. GetSession (). The getAttribute (Constant. USER_IN_SESSION);
If (object==null) {
Resp. SendRedirect ("/system/login ");
return false;
} else {
return true;
}
}
}


3. Configure interceptor




CodePudding user response:

Is it still write XML configuration spring project? Not all in the use of s (pring) b (oot)
  • Related