t:上传文件时fileInputUpload为null

时间:2011-11-16 02:26:09

标签: exception jsf upload null tomahawk

我正在使用tomahawk(1.1.11)和Mojarra(2.1.4)来开发一个JSF应用程序。当我上传小文件(kb)时它工作正常,但是当我上传大约160Mb的文件时,它会发送错误 null source

到目前为止,这是我的代码:

    <h:form id="menuForm" enctype="multipart/form-data">
        <h:outputLabel for="option" value="Acciones disponibles: " />
        <h:selectOneMenu id="option"
                         value="#{uploadFile.option}">
            <f:selectItem itemLabel="Seleccione una opción..." itemValue="null" />
            <f:selectItems value="#{uploadFile.options}" />
            <f:ajax render="@form" execute="@form" />
        </h:selectOneMenu>

        <h:panelGrid id="dataLoad" columns ="3" 
                     rendered="#{uploadFile.option == 'Agregar información (sin validación).' ||
                                 uploadFile.option == 'Cargar información completa (con validación).' || 
                                 uploadFile.option == 'Cargar solo información errónea (con validación).'}">
            <h:outputLabel for="upfile" value="Archivo: " />
            <t:inputFileUpload id="upfile" 
                               value="#{uploadFile.upFile}" />
            <h:panelGroup/>
            <h:panelGroup/>
            <h:commandButton value="Continuar"
                             onclick="return confirmation()"
                             action="#{uploadFile.upload}" />
        </h:panelGrid>

        <h:panelGrid id="dataValidate" columns="3"
                     rendered="#{uploadFile.option == 'Validar información actual.'}">
            <h:commandButton value=" Validar " action="#{uploadFile.validate()}"/>
        </h:panelGrid>

        <h:panelGrid id="listFiles" columns="3"
                     rendered="#{uploadFile.option == 'Visualizar todos los archivos.'}">
            <t:tree2 id="tree" value="#{listFiles.treeRoot}"
                     var="node" varNodeToggler="t" 
                     clientSideToggle="false">
                <f:facet name="folder">
                    <h:panelGroup>
                        <t:graphicImage value="images/folderOpen.png"
                                        rendered="#{t.nodeExpanded}"
                                        border="0" />
                        <t:graphicImage value="images/folderClose.png"
                                        rendered="#{!t.nodeExpanded}"
                                        border="0" />
                        <h:outputText value="#{node.description}"
                                      styleClass="nodeFolder" />
                    </h:panelGroup>
                </f:facet>
                <f:facet name="file">
                    <h:panelGroup>
                        <h:commandLink immediate="true"
                                       action="#{listFiles.download(node.identifier)}">
                            <t:graphicImage value="images/file.png" border="0" />
                            <h:outputText value="#{node.description}" />
                        </h:commandLink>
                    </h:panelGroup>
                </f:facet>
            </t:tree2>
        </h:panelGrid>
    </h:form>

实际上我需要上传大于此的文件,甚至高达2 Gb。有什么建议吗?

更新

这是完整的堆栈跟踪

java.lang.IllegalArgumentException: null source
at java.util.EventObject.<init>(Unknown Source)
at javax.faces.event.SystemEvent.<init>(SystemEvent.java:71)
at javax.faces.event.ComponentSystemEvent.<init>(ComponentSystemEvent.java:73)
at javax.faces.event.PostRestoreStateEvent.<init>(PostRestoreStateEvent.java:73)
at com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:271)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:257)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:349)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:269)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1773)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

更新

我也会放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>
    </context-param>
    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
        <param-value>false</param-value>
    </context-param>
    <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>/faces/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>

    <filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>

        <init-param>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>5g</param-value>
        </init-param>
        <init-param>
            <param-name>uploadThresholdSize</param-name>
            <param-value>500m</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>/faces/*</servlet-name>
    </filter-mapping>
</web-app>

2 个答案:

答案 0 :(得分:0)

最后!我找到了问题的原因,但我不确定发生了什么,所以我想如果有人可以帮我解决这个问题。

首先,问题出在 web.xml 文件中。最后我有点像

<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <servlet-name>/faces/*</servlet-name>
</filter-mapping>

所以我从web.xml中删除它,它上传文件没有任何问题!我认为,服务器与此`filter-mappingservlet-mapping混淆了。我希望有经验的人帮助我(以及所有读这个问题的人)清除这个问题。

答案 1 :(得分:0)

Rabbit你可以从正在使用的apache commons fileupload jar中删除FileUploadBase文件

并根据需要设置最大文件和请求大小限制。这是我在搜索任何配置项以自定义上限之后克服大小限制所做的操作文件上传1.2.1 100mb限制它对我施加的影响。

你可以关闭src http://commons.apache.org/proper/commons-fileupload//index.html

只需修改源文件重新编译并覆盖fileupload jar中的现有类文件

确保您获得与您正在使用的文件上传版本完全对应的源zip,否则您可能会遇到问题