Request.getParts 在没有多部分配置的情况下被调用。向 servlet 添加 @MultipartConfig,或向 web.xml 添加 multipart-config 元素

djm*_*jmj 4 jsf file-upload jsf-2.2

我想使用 JSF 本机文件上传组件。如果可能,使用 AJAX。但我无法让它工作。

上传文件

<h:form enctype="multipart/form-data">
    <h:inputFile value="#{bean.file}" required="true"/>
    <h:commandButton action="#{bean.importFile()}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)

我认为使用 JSF 2.2 不应该出现以下错误。

Request.getParts在没有多部分配置的情况下调用。将 a 添加@MultipartConfig到 servlet,或将 multipart-config 元素添加到 web.xml

环境

  • 玻璃鱼 4.1
  • 莫哈拉 2.2.4
  • Primefaces 5.0

kol*_*sus 5

出于某些 [不明显] 的原因,为 JSF-2.2@MultipartConfig添加的那些FacesServlet并不适合您。因此,您现在需要手动将多部分配置添加到您的 web.xml 中,如下所示:

 <multipart-config>
      <location>/tmp</location>
      <max-file-size>20848820</max-file-size>
      <max-request-size>418018841</max-request-size>
      <file-size-threshold>1048576</file-size-threshold>
 </multipart-config>
Run Code Online (Sandbox Code Playgroud)