gpt4 book ai didi

java - Richfaces 文件上传 ViewExpiredException

转载 作者:行者123 更新时间:2023-12-04 05:32:17 30 4
gpt4 key购买 nike

我有一个使用rich:fileUpload 上传文件的页面。对于较小的文件,这可以正常工作,但是对于较大的文件 (+80MB),我通常会收到 ViewExpiredException。我已经尝试寻找解决方案,但我没有找到任何解决此问题的方法。

  • Richfaces 3.3.3.3
  • Tomcat 6.0.20
  • Spring 2.5.6
  • JSF 1.2_14

  • 页面bean:
    @Component
    @Scope("request")
    public class Bean {
    ...
    }

    jspx:
    <?xml version="1.0" encoding="UTF-8" ?>
    <jsp:root omit-xml-declaration="true"
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
    xmlns:rich="http://richfaces.ajax4jsf.org/rich"
    xmlns:ui="http://java.sun.com/jsf/facelets" version="2.0">
    <rich:panel styleClass="formPanel">
    <h:form id="docForm">
    <ui:param name="doc" value="#{pb.newDoc}" />
    <h:panelGrid columns="2" columnClasses="formTableLabel, formTableField">
    ...
    <h:outputLabel for="fileUpload" value="#{labels['file']}*" />
    <h:panelGroup>
    <rich:fileUpload required="true" ajaxSingle="true"
    fileUploadListener="#{pb.uploadDocument}" id="fileUpload"
    autoclear="false" immediateUpload="true" noDuplicate="true"
    addControlLabel="#{labels['browse']}">
    <a4j:support event="onclear" reRender="fileUpload" ajaxSingle="true"
    oncomplete="$('docForm:fileUpload').component.currentInput.enable()"/>
    </rich:fileUpload>
    <h:message for="fileUpload" styleClass="errorMessage"
    showDetail="false" showSummary="true" />
    </h:panelGroup>
    ...

    web.xml:
    ...
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
    </context-param>
    <context-param>
    <param-name>facelets.SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>facelets.BUFFER_SIZE</param-name>
    <param-value>500000</param-value>
    </context-param>
    <context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>ALL</param-value>
    </context-param>
    <context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>ALL</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.jspx</param-value>
    </context-param>
    <context-param>
    <description>
    Context parameter specifically for facelets, lists available tag libraries.
    </description>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>
    /WEB-INF/taglibs/authorization.taglib.xml;
    /WEB-INF/taglibs/taskscreen.taglib.xml
    </param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/config/faces-config.xml</param-value>
    </context-param>
    <context-param>
    <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
    <param-value>com.sun.facelets.FaceletViewHandler</param-value>
    </context-param>
    <filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    <init-param>
    <param-name>forceparser</param-name>
    <param-value>false</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>FacesServlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <welcome-file-list>
    <welcome-file>start/start.jspx</welcome-file>
    </welcome-file-list>
    <error-page>
    <error-code>500</error-code>
    <location>/error.jspx</location>
    </error-page>
    <error-page>
    <error-code>403</error-code>
    <location>/access-denied.jspx</location>
    </error-page>
    <error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/expired.jsf</location>
    </error-page>
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    ...

    堆栈跟踪:
    SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution:   javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@22075431]
    2012-09-13 16:43:46,945 [qtp130437654-18] ERROR org.ajax4jsf.webapp.BaseXMLFilter doXmlFilter - Exception in the filter chain
    javax.servlet.ServletException: viewId:/data/includes/doc.jspx - View /data/includes/doc.jspx could not be restored.
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:521)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1207)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:367)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:433)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:118)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:490)
    at org.eclipse.jetty.server.session.SessionHandler.handle(SessionHandler.java:179)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:928)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:370)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:862)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:116)
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:331)
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:115)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:64)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:278)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:110)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at com.doc.filter.IEFilter.doFilter(IEFilter.java:33)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at com.doc.portal.filter.ExceptionRedirectFilter.doFilter(ExceptionRedirectFilter.java:28)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:110)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at com.doc.filter.UTF8Filter.doFilter(UTF8Filter.java:20)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1178)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:433)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:118)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:456)
    at org.eclipse.jetty.server.session.SessionHandler.handle(SessionHandler.java:179)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:928)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:370)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:862)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:116)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:115)
    at org.eclipse.jetty.server.Server.handle(Server.java:330)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:557)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:947)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:736)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:203)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:413)
    at org.eclipse.jetty.server.bio.SocketConnector$Connection.run(SocketConnector.java:229)
    at org.eclipse.jetty.server.ssl.SslSocketConnector$SslConnection.run(SslSocketConnector.java:648)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:435)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: javax.faces.application.ViewExpiredException: viewId:/data/includes/doc.jspx - View /data/includes/doc.jspx could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:189)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:102)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
    ... 75 more

    有人知道如何解决这个问题吗?谢谢。

    最佳答案

    这可能不是您想听到的,但标准 HTTP 协议(protocol)在上传大文件时效果不佳。通常在对等套接字应用程序中,客户端和服务器都可以保持连接健康并在大传输期间保持一切 Activity 。然而,对于 HTTP 和 Web,客户端通常唯一有状态的就是它的 cookie。客户端无法知道它的 cookie 是否仍然有效(更正:除非它们被明确设置为在特定日期过期),直到将它们提供给服务器并得到带有结果的响应。

    因此,正因为如此,服务器需要对 session 的生命周期强加一个时间线,并且在该时间过去之后,它会为 session 折腾状态信息。由于典型的 Internet 连接的上传速度往往比下载速度稍慢,而且在等待大文件上传时 session 失效并不罕见。

    你有三个选择:

  • 您增加了服务器上的 session 超时期限。也许这会给你足够的时间。
  • 您使用富客户端界面(Flash、Applet、Silverlight 等),并通过在您的网页上上传文件来使用此富客户端。这样做的好处是您可以将大文件分解为可管理的二进制 block ,并一次将它们与 session cookie 一起发送到服务器。这些成功的 block 请求中的每一个都将具有在整个传输过程中保持 session Activity 的效果。您的服务器在收到最终 block 后可以重新组装您的大文件并将其持久化。
  • 除了利用 HTML5 和 JS 的强大功能之外,做与 #2 基本相同的事情。以下是一个开源 Javascript 库,它利用 HTML5 技术也将大文件分解成 block 并协助在服务器上重新组装它们。 http://steffentchr.dk/post/7454042318/resumable-js这种方法的一些缺点是,由于它使用的是 HTML5,它只能在现代浏览器上工作,因此对像 IE7 这样的旧浏览器的支持是有问题的。

  • 关于第 3 点的另一个注意事项是,将这段 Javascript 代码包含在自定义或复合 JSF 组件中并非不可能,这将允许您在客户端和服务器之间建立更简化的接口(interface)。

    另请参阅以下问题: Upload of very large files

    关于java - Richfaces 文件上传 ViewExpiredException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12421610/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com