session超时
登陆后在session中设置loginForm成功,但在web.xml中设置了session超时,我就想在服务器在超时(超时时用户又不知道)之前能再将loginForm的一个属性又设置到session中,并在Filter中进行判断再做相应的跳转。
1.在web.xml中配置:
<session-config>
<session-timeout>20</session-timeout>
</session-config>
2.登录时在sessin中设值loginForm
3.当超时那一刻,我希望通过Listener来监听到并重新在session中设值为"mlFlag",该值为loginForm的一个属性:
该选择HttpSessionListener,HttpSessionAttributeListener,HttpSessionBindingListener
的哪一个监听器来设置“mlFlag”。
4.还要在SessionFilter的doFilter方法中获得“mlFlag”:
HttpSession session = ((HttpServletRequest) request).getSession();
if (session.getAttribute("loginForm") == null)
{
String ml = (String)session.getAttribute("mlFlag");
if ( "9".equals(ml)){
response.sendRedirect(hreq.getContextPath() + "/timeout.jsp?mlFlag=" + ml);
}else {
response.sendRedirect(hreq.getContextPath() + "/timeout.jsp?mlFlag=-1");
}
}
我用如下测试过:
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
LoginForm loginForm=(LoginForm)session.getAttribute("loginForm");
session.setAttribute("mlFlag", loginForm.getManagerLevel());
}
在SessionFilter中String ml = (String)session.getAttribute("mlFlag")
这时"ml"为null
先感谢各位朋友了!