Problem domain: the login user has not interacted with the server for a long time. If the operation is performed again, the system prompts "timeout". Please log on again.
Solution: session timeout settings and struts interceptor intercept interactive operations
Implementation
Use web. xml configuration to set session Timeout
<Session-config>
<Session-timeout> 10 </session-timeout>
</Session-config>
Struts interceptor code implementation
Public class SessionIterceptor extends actinterceptor {@ Override public String intercept (ActionInvocation actionInvocation) throws Exception {ActionContext ctx = ActionContext. getContext (); Map session = ctx. getSession (); Action action = null; // this step is written because some actions inherit ActionSupport and some actions inherit BaseAction if (actionInvocation. getAction () instanceof Action) action = (Action) actionInvocation. getAction (); if (action instanceof LoginAction) {return actionInvocation. invoke ();} Operator operator = (Operator) session. get ("OPERATOR_SESSION"); if (operator = null) {HttpServletRequest request = (HttpServletRequest) actionInvocation. getInvocationContext (). get (ServletActionContext. HTTP_REQUEST); request. setAttribute ("timeoutMSG", "timeout, please log on again"); return "timeoutSession";} else {return actionInvocation. invoke ();}}}
Page capture transfer prompt information
<% @ Taglib prefix = "s" uri = "/struts-tags" %>
<S: property value = "# attr. timeoutMSG"/> <br/>
Configuration in struts. xml
<Package name = "myInterceptor" extends = "json-default"> <interceptors> <! -- Timeout interceptor --> <interceptor name = "timeoutSession" class = "com. sunyard. ices. web. interceptors. SessionIterceptor"> </interceptor> <! -- Interceptor stack --> <interceptor-stack name = "timeoutStack"> <interceptor-ref name = "timeoutSession"> </interceptor-ref> <interceptor-ref name = "defaultStack"> </interceptor-ref> </interceptor-stack> </interceptors> <! -- Configure the default interceptor --> <default-interceptor-ref name = "timeoutStack"/> <! -- Global Non-Logon interception redirects to the logon page --> <global-results> <result name = "timeoutSession">/login. jsp </result> </global-results> </package>
A package is specially configured because a large number of include operations are used. In other struts configuration files, you only need to inherit the package.
<package name="operatora" extends="myInterceptor">
So far, the problem has been solved. This is the first time that a beginner writes a blog post. To enhance memory, it is also convenient for beginners.