2009年3月25日星期三

WLS_063:Session Timeout的设置

运行开发环境:WebLogic Server 12c开发版(12.1.1.1.0) + OEPE 12c(12.1.1.1.0)

配置Session Timeout的地方有两个:web.xml和weblogic.xml。
为了更清楚地了解Sesstion何时Timeout,我使用了一个SessionListener监听Session的创建和失效时间。

1. 在web.xml中配置Session Timeout,单位是分钟。
<session-config>
    <session-timeout>1</session-timeout>
</session-config>

运行index.jsp,Console输出如下:
%%%%%%%%%% Session Created at Thu Oct 18 11:19:06 CST 2012
%%%%%%%%%% Session Destroyed at Thu Oct 18 11:19:07 CST 2012
%%%%%%%%%% Session Created at Thu Oct 18 11:19:13 CST 2012
%%%%%%%%%% Session Destroyed at Thu Oct 18 11:21:10 CST 2012
%%%%%%%%%% name = username,  value= ssouser

可以发现一个比较奇怪的事实:Session的生命周期比设置的约长了1分钟,大约2分钟。

2.  在weblogic.xml中配置Session Timeout,单位是秒。
去掉web.xml中Session Timeout的配置,只在weblogic.xml中配置如下:
<wls:session-descriptor>
    <wls:timeout-secs>180</wls:timeout-secs>
</wls:session-descriptor>

运行index.jsp,Console输出如下:
%%%%%%%%%% Session Created at Thu Oct 18 11:44:39 CST 2012
%%%%%%%%%% Session Created at Thu Oct 18 11:44:48 CST 2012
%%%%%%%%%% Session Destroyed at Thu Oct 18 11:44:48 CST 2012
%%%%%%%%%% Session Destroyed at Thu Oct 18 11:48:37 CST 2012
%%%%%%%%%% name = username,  value= ssouser

可以发现Session的生命周期比设置的还是约长了1分钟,大约4分钟。

3. 进一步说明
(1)如果在web.xml和weblogic.xml中都配置了Session Timeout,将以web.xml中配置为准。
(2)网上有人说,在web.xml中设置session-timeout为-2,表示将使用weblogic.xml中的设置;设置session-timeout为-1,表示Session将永不过期,忽略weblogic.xml中的设置。
但我的实验结果是:只要设置session-timeout为负值,Session似乎就会永不过期。

4. 结论
(1)不要在web.xml和weblogic.xml中同时配置Session Timeout,容易引起混淆。
(2)设置Session永不过期也不是一个好的方案,还是按实际需要设置。

Project 下载:SecurityWithSessionWeb.7z
参考文献:
1. http://blog.csdn.net/e_wsq/article/details/7555667

没有评论: