继续解决this problem,我已经用 MyFaces 替换了 Mojarra 并升级了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>
你有没有遇到过这样的错误报告?
答案 0 :(得分:4)
回复可能有点迟,但我遇到了同样的问题,我花了很多时间来解决它。所以,我认为这可能有助于其他人。
默认情况下,MyFaces
执行状态序列化,即使状态正在服务器上保存,而Mojarra
则没有。因此,如果您有一些不可序列化的bean,或者使用其他不可序列化的bean,您将看到该错误(服务器无法序列化该对象)。
您可以停用序列化,以便MyFaces
可以像Mojarra
一样工作。
请检查此链接:ViewScoped Bean cause NotSerializableException
答案 1 :(得分:3)
您在这里遇到的问题是典型的,并且是由于默认情况下MyFaces生成随机密码以对视图状态进行编码而引起的。每次服务器重新启动时,都会生成一个新的随机密码。
要解决此问题,您需要设置一些web配置参数,特别是org.apache.myfaces.SECRET和org.apache.myfaces.MAC_SECRET,因此每次重新启动服务器时都会使用相同的密码。 Mojarra也有类似的东西,但我现在不记得param这个名字。
查看此页面Secure Your Application with MyFaces。在那里,您可以找到设置加密所需的所有详细信息。
您可以通过订阅Users and Dev Mailing Lists
发送有关MyFaces的问题答案 2 :(得分:2)
如上所述,在另一个答案中,需要定义SECRET。我按照Secure_Your_Application的说明进行操作。我将以下行添加到web.xml
(相应地更改了秘密)。并且不要忘记下载无限强度的JCE策略文件。
<context-param>
<param-name>org.apache.myfaces.ALGORITHM</param-name>
<param-value>AES</param-value>
</context-param>
<!-- Defines the secret (Base64 encoded) used to initialize the secret key
for encryption algorithm. The size of it depends on the algorithm used for encryption -->
<context-param>
<param-name>org.apache.myfaces.SECRET</param-name>
<param-value>MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIz</param-value>
</context-param>
<!-- Define the initialization code (Bas64 encoded) that are used to initialize the secret key used
on the Message Authentication Code algorithm. The size of it depends on the algorithm used for mac calculation -->
<context-param>
<param-name>org.apache.myfaces.MAC_SECRET</param-name>
<param-value>YWJjZDEyMzQ=</param-value>
</context-param>
答案 3 :(得分:0)
解决方案:我必须考虑哪些类应该是可序列化的,哪些不是。
答案 4 :(得分:0)
我通常会收到此错误。我正在使用myfaces 1.2和websphere 7,但后来我没有重启服务器。我首先停止服务器,然后再次启动而不是重新启动。这很有用。