webwork的 session过期问题
webwork 中,我们设定的是当20分钟无人操作时,HttpSession自动过期。需要一个拦截器,当HttpSession20分钟后自动过期时,跳到一个重新登陆的页面
1、拦截器
/**
* 标题:判断session过期的拦截器文件
* 说明:判断session过期的拦截器文件
*/
public class SessionValidation extends AbstractInterceptor {
/**
*
*/
private static final long serialVersionUID = 1L;
private static Log log = LogFactory.getLog(SessionValidation.class);
public void init() {
log.info("<<<初始化拦截器");
}
public void destory() {
log.info("<<<销毁拦截器");
}
public String intercept(ActionInvocation ai) throws Exception {
final String LOGON_PAGE = "logon";
Object action = ai.getAction();
// 确认Session中是否存在LOGIN
//Map session = ai.getInvocationContext().getSession();
// 对LogonAction不做该项拦截
if (action instanceof LogonAction) {
//log.info("exit check login, because this is login action.");
return ai.invoke();
}
SysUser login = (SysUser) HttpSessionUtils.get(SysUser.SES_KEY);
if (login != null) {
// 存在的情况下进行后续操作。
//log.info("already login!");
return ai.invoke();
} else {
// 否则终止后续操作,返回LOGIN
log.info("no login, forward login page!");
return LOGON_PAGE;
}
}
}
2、页面
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title><s:text name="titleKey"/></title>
<link rel="stylesheet" type="text/css" href="<s:url value="/css/msoft.css"/>">
<script language="javascript">
function funcChgTarget(){
with(document.forms[0]){
target = "_parent" ;
}
}
</script>
</head>
<body>
<center>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror/>
<s:form action="logon" validate="false">
<center>
<p> </p>
<table border=0>
<tr><td><font color="red" size="3">session过期,请重新登陆!</font></td></tr>
<tr><td></td></tr>
<tr><td align="center"><s:submit action="logon" key="button.logon" onclick="funcChgTarget()" cssClass="Button"/></td></tr>
</table>
</center>
</s:form>
</center>
</body>
</html>