Assume that the session becomes invalid after the user logs on to the system for a period of time. If the user logs on to the system, the user must jump to the logon page and log on again.
General Solution:
(1) When a user logs on successfully for the first time, the user object is stored in the session, for example, session. setatti.pdf ("loginuser", user );
(2) define the Interceptor to intercept all URL requests and then obtain the loginuser object. If the object does not exist, the session expires:
import org.springframework.stereotype.Repository;import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;@Repositorypublic class LoginInterceptor extends HandlerInterceptorAdapter {@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {Object obj = request.getSession().getAttribute("loginUser");if(obj==null){request.getRequestDispatcher("/login.jsp").forward(request, response); return false;}else{return super.preHandle(request, response, handler);}}}
If the session becomes invalid, the system will jump to login. jsp and request to log on again.
(3) configure the Interceptor:
<mvc:interceptors><mvc:interceptor><mvc:mapping path="/*.html"/><bean class="com.xx.xxx.util.LoginInterceptor" /></mvc:interceptor></mvc:interceptors>
In this way, when a request ends with *. html, it is first intercepted by the logininterceptor.
(Study notes)