在struts2 中通过ActionContext访问Session对象
通过com.opensymphony.xwork2.ActionContext取 如先获取request HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE); 那么取session就和struts1一样了 HttpSession session = request.getSession(); 操作都一样的 另外在action 内往session中保存数据,可以直接用下面的方法: ActionContext.getContext().getSession().put(key, value) key object型 value object型
在tomcat中设置session过期时间
1. 在\conf\web.xml中通过参数指定:
<session-config>
<session-timeout>180</session-timeout>
</session-config>
单位为分钟。
2. 在程序中通过servlet api直接修改:
HttpSession session = request.getSession();
session.setMaxInactiveInterval(180*60);
单位为秒,设置为-1永不过期。
浙公网安备 33010602011771号