我有一个监听器记录 sessionCreated 和 sessionDestroyed。
日志表明,每次会话超时,首先创建一个新会话,然后抛出 viewExpired-Exception,然后再次创建一个新会话!
这意味着浏览器与两个会话相关联,但应该只存在一个!
正常的行为是:
抛出异常,然后创建一个新会话(反之亦然)。
您如何看待默认行为?这可能是一个错误吗?
这是日志:
09:22:52,640 INFO [com.MyListener] (http--0.0.0.0-8080-1) HttpSessionEvent: session created
09:22:52,641 INFO [com.MyListener] (http--0.0.0.0-8080-1) session org.apache.catalina.session.StandardSessionFacade@61a19e4e
09:22:52,642 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.getMaxInactiveInterval 60 sec.
09:22:52,643 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.getLastAccessedTime: 09:22:52
09:22:52,643 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.isNew true
09:22:52,644 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.getCreationTime(): 09:22:52
09:22:52,645 INFO [com.MyAdmin] (http--0.0.0.0-8080-1) number of sessions: 1
09:22:52,645 INFO [com.MyAdmin] (http--0.0.0.0-8080-1) session org.apache.catalina.session.StandardSessionFacade@61a19e4e
09:22:52,663 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/serview].[Faces Servlet]] (http--0.0.0.0-8080-1) Servlet.service() for servlet Faces Servlet threw exception: javax.faces.application.ViewExpiredException: viewId:/login.html ..
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:205) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_01]
09:22:58,053 INFO [com.MyListener] (http--0.0.0.0-8080-1) HttpSessionEvent: session created
09:22:58,053 INFO [com.MyListener] (http--0.0.0.0-8080-1) session org.apache.catalina.session.StandardSessionFacade@423bd361
09:22:58,054 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.getMaxInactiveInterval 60 sec.
09:22:58,055 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.getLastAccessedTime: 09:22:58
09:22:58,055 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.isNew true
09:22:58,056 INFO [com.MyListener] (http--0.0.0.0-8080-1) session.getCreationTime(): 09:22:58
09:22:58,056 INFO [com.MyAdmin] (http--0.0.0.0-8080-1) number of sessions: 2
09:22:58,057 INFO [com.MyAdmin] (http--0.0.0.0-8080-1) session org.apache.catalina.session.StandardSessionFacade@423bd361
09:22:58,058 INFO [com.MyAdmin] (http--0.0.0.0-8080-1) session org.apache.catalina.session.StandardSessionFacade@61a19e4e
你看,会话org.apache.catalina.session.StandardSessionFacade@61a19e4e是无用的创建。我怎样才能避免这种情况?
顺便说一句,我已经相应地捕获了异常:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/error_expired.html</location>
</error-page>