我想使用 JSF native 文件上传组件。如果可能的话使用 AJAX。但我无法让它工作。
文件上传
<h:form enctype="multipart/form-data">
<h:inputFile value="#{bean.file}" required="true"/>
<h:commandButton action="#{bean.importFile()}"/>
</h:form>
我认为使用 JSF 2.2 不应出现以下错误。
Request.getParts
is called without multipart configuration. Either add a@MultipartConfig
to the servlet, or a multipart-config element to web.xml
环境
- 玻璃鱼4.1
- 莫贾拉 2.2.4
- Primefaces 5.0
最佳答案
由于某些[不明显]的原因,添加到 JSF-2.2 的 FacesServlet
中的 @MultipartConfig
并没有为您发挥作用。因此,您现在需要 manually add the multipart configuration to your 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>
关于jsf - 调用 Request.getParts 时无需进行多部分配置。将 @MultipartConfig 添加到 servlet,或者将 multipart-config 元素添加到 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26205024/