【问题标题】:Jsf inputFile file sizejsf inputFile文件大小
【发布时间】:2016-10-05 11:39:39
【问题描述】:

我的表单中有这个输入文件字段来上传文件。

    <h:form id="stammdaten" enctype="multipart/form-data">
<h:inputFile id="profileImage" value="#{stammdatenController.file}" />
</h:form>

以上代码正确上传文件。但问题是如果我选择大于 1Mb 的文件,那么它不会被上传。只有小于 1Mb 的文件才能正确上传。

如何将此文件上传限制增加到 2Mb?

编辑: 我的 web.xml

<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>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

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

    <context-param>
        <param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
        <param-value>0</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

还有我的支持 bean:

private Part file;

    public void upload() throws IOException{
        try (InputStream input = file.getInputStream()) {
            FileUtils.copyToFile(input, new File("/home/john/Pictures/uploads/test.jpg"));
        }
}

【问题讨论】:

  • 关于使用过的 JSF 的零信息(h:inputFile 在 Mojarra 中有(有?)这么多问题),关于使用过的服务器的零信息(这些问题几乎总是与服务器/配置相关),关于错误消息(您选择了一个文件,但绝对没有任何反应?)。 web.xml 中有 multipart-config 吗?
  • 我已经用更多信息更新了我的问题。请注意,我没有为文件上传做任何服务器/配置。而且,如果我提交表单,服务器日志上没有错误,表单提交后我被重定向到同一页面
  • 服务器信息很重要,因为所有服务器都有帖子大小限制,需要通过服务器特定设置进行配置。然而,1MB 相当低(当然,假设您的意思是 MB 而不是 Mb)。
  • 我正在使用内置于tomcat服务器的spring boot。所以我添加了spring.http.multipart.max-file-size=10Mb # Max file size.spring.http.multipart.max-request-size=10Mb # Max request size.,在web.xml中我还根据下面的答案添加了相同的大小。我也尝试过 primefaces 并遇到了同样的 1MB 问题

标签: jsf file-upload jsf-2


【解决方案1】:

更新您的web.xml

 <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <multipart-config>
        <max-file-size>put_your_desired_value</max-file-size>
        <max-request-size>also_here_request_size</max-request-size>
        <file-size-threshold>and_here_in_bytes</file-size-threshold>
    </multipart-config>
</servlet>

【讨论】:

  • 不幸的是,这不起作用。我想我在这里遗漏了一些简单的东西。提交表单后,页面刷新。它实际上并没有将表单发送到服务器。
猜你喜欢
  • 2013-08-30
  • 1970-01-01
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多