在前一个实验的基础上,只要修改web.xml中的WARNING_BEFORE_TIMEOUT值就可以,比如默认的120秒。
其它的地方都不需要修改。
1. web.xml
<context-param>
<param-name>oracle.adf.view.rich.sessionHandling.WARNING_BEFORE_TIMEOUT</param-name>
<param-value>120</param-value>
</context-param>
<filter>
<filter-name>SessionTimeOutFilter</filter-name>
<filter-class>view.SessionTimeOutFilter</filter-class>
<init-param>
<param-name>SessionTimeoutRedirect</param-name>
<param-value>index.jsf</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SessionTimeOutFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
2. 运行效果
session过期前两分钟弹出“失效警告”窗口,如果没有理会,那么session过期后,警告窗口自动关闭,然后弹出“页面失效”窗口,点击确定后,会Redirect到你指定的页面,我这里是index.jsf。
我的实验结果发现,后台会报出一个异常:
java.lang.IllegalStateException: HttpSession is invalid
at weblogic.servlet.internal.session.SessionData.getAttributeNames(SessionData.java:483)
at view.SessionTimeOutSessionListener.sessionDestroyed(SessionTimeOutSessionListener.java:30)
at weblogic.servlet.internal.EventsManager.notifySessionLifetimeEvent(EventsManager.java:276)
at weblogic.servlet.internal.session.SessionData.remove(SessionData.java:971)
at weblogic.servlet.internal.session.MemorySessionContext.invalidateSession(MemorySessionContext.java:69)
Truncated. see log file for complete stacktrace
这是因为我定义了一个SessionListener,用来监听session何时创建,何时失效。
但我不知道为何sessionDestroyed时,会抛出这个异常,不过页面没有受到影响。
3. SessionTimeOutSessionListener
package view;
import java.util.Enumeration;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionTimeOutSessionListener implements HttpSessionListener {
private HttpSession session = null;
public void sessionCreated(HttpSessionEvent event) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% Session Created at " + new java.util.Date());
session = event.getSession();
String name = null;
Object value = null;
for (Enumeration enu = session.getAttributeNames(); enu.hasMoreElements(); ) {
name = (String)enu.nextElement();
value = session.getAttribute(name);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% name = " + name + ", value= " + value);
}
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% Session Destroyed at " + new java.util.Date());
String name = null;
Object value = null;
for (Enumeration enu = session.getAttributeNames(); enu.hasMoreElements(); ) {
name = (String)enu.nextElement();
value = session.getAttribute(name);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% name = " + name + ", value= " + value);
}
}
}
2. 运行效果
session过期前两分钟弹出“失效警告”窗口,如果没有理会,那么session过期后,警告窗口自动关闭,然后弹出“页面失效”窗口,点击确定后,会Redirect到你指定的页面,我这里是index.jsf。
我的实验结果发现,后台会报出一个异常:
java.lang.IllegalStateException: HttpSession is invalid
at weblogic.servlet.internal.session.SessionData.getAttributeNames(SessionData.java:483)
at view.SessionTimeOutSessionListener.sessionDestroyed(SessionTimeOutSessionListener.java:30)
at weblogic.servlet.internal.EventsManager.notifySessionLifetimeEvent(EventsManager.java:276)
at weblogic.servlet.internal.session.SessionData.remove(SessionData.java:971)
at weblogic.servlet.internal.session.MemorySessionContext.invalidateSession(MemorySessionContext.java:69)
Truncated. see log file for complete stacktrace
这是因为我定义了一个SessionListener,用来监听session何时创建,何时失效。
但我不知道为何sessionDestroyed时,会抛出这个异常,不过页面没有受到影响。
3. SessionTimeOutSessionListener
package view;
import java.util.Enumeration;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionTimeOutSessionListener implements HttpSessionListener {
private HttpSession session = null;
public void sessionCreated(HttpSessionEvent event) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% Session Created at " + new java.util.Date());
session = event.getSession();
String name = null;
Object value = null;
for (Enumeration enu = session.getAttributeNames(); enu.hasMoreElements(); ) {
name = (String)enu.nextElement();
value = session.getAttribute(name);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% name = " + name + ", value= " + value);
}
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% Session Destroyed at " + new java.util.Date());
String name = null;
Object value = null;
for (Enumeration enu = session.getAttributeNames(); enu.hasMoreElements(); ) {
name = (String)enu.nextElement();
value = session.getAttribute(name);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%% name = " + name + ", value= " + value);
}
}
}
没有评论:
发表评论