记录后立即显示ViewExpiredException

时间:2014-05-17 21:49:28

标签: jsf jsf-2 viewexpiredexception expired-sessions

我读到这是一个过期会话的问题,但在我的情况下它是不可能的,因为会话只是在抛出异常时打开:我进入登录页面,填写表格并提交。之后我得到ViewExpiredException。我该怎么做才能解决问题?

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>

    <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
    <param-value>false</param-value>

    <param-name>com.sun.faces.numberOfLogicalViews</param-name>
    <param-value>100</param-value>

</context-param>
<listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>pages/login.xhtml</welcome-file>
</welcome-file-list>

<security-constraint>
    <display-name>Admin</display-name>
    <web-resource-collection>
        <web-resource-name>Admin</web-resource-name>
        <url-pattern>/pages/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>
<security-constraint>
    <display-name>User</display-name>
    <web-resource-collection>
        <web-resource-name>User</web-resource-name>
        <url-pattern>/pages/user/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>

<security-role>
    <role-name>admin</role-name>
</security-role>
<security-role>
    <description/>
    <role-name>user</role-name>
</security-role>

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/pages/login.xhtml</form-login-page>
        <form-error-page>/pages/errorLogin.xhtml?faces-redirect=true</form-error-page>
    </form-login-config>
</login-config>
<error-page>
    <error-code>403</error-code>
    <location>/pages/errorLogin.xhtml</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/pages/sessionExpired.xhtml</location>
</error-page>   
<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/pages/sessionExpired.xhtml</location>
</error-page>

1 个答案:

答案 0 :(得分:1)

尝试在您的web.xml中使用STATE_SAVING_METHOD客户端

<context-param>
   <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
   <param-value>client</param-value>
</context-param>

如果您想坚持服务器模式,请尝试增加您的观看次数:

<context-param>  
        <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>  
        <param-value>40</param-value>  
        <description>Only applicable if state saving method is "server" (= default).  
                     Defines the amount (default = 20) of the latest views are stored in session.  
        </description>  
</context-param>