服务器重新启动后出现 JSF 问题:找不到已保存的视图状态
继续解决这个问题,我已经替换了Mojarra 通过 MyFaces 并升级 JDK,当我在服务器重新启动后继续处理表单时,出现以下错误:
发生错误:
/food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
Caused by:
javax.faces.application.ViewExpiredException - /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
控制台:
SEVERE: Exception loading sessions from persistent storage
java.lang.IllegalStateException: unread block data
at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2376)
堆栈跟踪:
javax.faces.application.ViewExpiredException: /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
还有我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>PORTAL</display-name>
<session-config>
<session-timeout>180</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
</web-app>
你没有遇到过这样的错误报告吗?
Continue solving this problem, I've replaced Mojarra by MyFaces and upgrade JDK and when I continue working on form after restart of server, following error appears:
An Error Occurred:
/food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
Caused by:
javax.faces.application.ViewExpiredException - /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
Console:
SEVERE: Exception loading sessions from persistent storage
java.lang.IllegalStateException: unread block data
at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2376)
Stack Trace:
javax.faces.application.ViewExpiredException: /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
And my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>PORTAL</display-name>
<session-config>
<session-timeout>180</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
</web-app>
Don't you ever met such error report?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
回复可能有点晚了,但我也遇到了同样的问题,并且花了相当长的时间来解决它。所以,我认为这可能对其他人有帮助。
默认情况下,
MyFaces
会序列化状态,即使状态保存在服务器上,而Mojarra
则不会。因此,如果您有一些不可序列化的 bean,或者正在使用其他不可序列化的 bean,您将看到该错误(服务器无法序列化该对象)。您可以禁用序列化,以便
MyFaces
将像Mojarra
一样工作。检查此链接:ViewScoped Bean 导致 NotSerializedException
This might be a bit late to reply, but I had the same problem and I spent quite some time to solve it. So, I thought this might help someone else.
By default,
MyFaces
does serialization of state, even when state is being saved on the server, whileMojarra
does not. So, if you have some beans that are not serializable, or which are using other beans that are not serializable, you will see that error (the server is not able to serialize the object).You can disable the serialization so
MyFaces
will work likeMojarra
.Check this link: ViewScoped Bean cause NotSerializableException
如前所述,在另一个答案中,需要定义秘密。我按照 Secure_Your_Application 中的说明进行操作。我将以下几行添加到
web.xml
(相应地更改机密)。并且不要忘记下载无限强度的 JCE 策略文件。As said, on the other answer, one need to define the SECRET. I followed the instructions at Secure_Your_Application. I added the below lines to
web.xml
(change the secrets accordingly). And dont forget to the to download the unlimited strength JCE policy files.您在这里遇到的问题是典型的,是因为默认情况下 MyFaces 生成一个随机密钥来编码视图状态而引起的。每次服务器重新启动时,都会生成一个新的随机秘密。
为了解决这个问题,您需要设置一些 Web 配置参数,特别是 org.apache.myfaces.SECRET 和 org.apache.myfaces.MAC_SECRET,因此每次重新启动服务器时都会使用相同的机密。 Mojarra 也有类似的东西,但我现在不记得参数名称了。
查看此页使用 MyFaces 保护您的应用程序。在那里您可以找到设置加密所需的所有详细信息。
您可以通过订阅用户和开发人员邮件列表来发送有关 MyFaces 的问题
The problem you are experienced here is typical, and is caused because by default MyFaces generates a random secret for encode the view state. Each time the server restart, a new random secret is generated.
To solve this, you need to setup some web config params, specially org.apache.myfaces.SECRET and org.apache.myfaces.MAC_SECRET, so the same secret is used each time your server is restarted. Mojarra has something similar too, but I don't remember the param name at this moment.
Check this page Secure Your Application with MyFaces. There you can find all details you need to setup your encryption.
You can send questions about MyFaces by subscribing to Users and Dev Mailing Lists
解决方案:我必须考虑哪些类应该被序列化,哪些类不应该被序列化。
SOLUTION: I had to consider which classes should be serializabled and which not.
我通常会收到此错误。我正在使用 myfaces 1.2 和 websphere 7,但后来我没有重新启动服务器。我首先停止服务器,然后再次启动而不是重新启动。那行得通。
I usually get this error. I am using myfaces 1.2 and websphere 7, but then I did not restart the server. I first stopped the server, then started again rather than doing a restart. That worked.