我从昨天开始使用Primefaces上传工具,但今天我开始用不同的文件扩展名测试它。令我惊讶的是,我能成功上传的唯一文件是.txt我不明白为什么会这样。我在网上看到了代码snipets,我认为我的代码几乎是一样的。我错过了什么吗?
这里有更多信息:
这是错误:
警告:StandardWrapperValve [Faces Servlet]:PWC1406:servlet的Servlet.service()Faces Servlet抛出异常 java.io.IOException:处理multipart / form-data请求失败。 \ uploaded \ upload_3be1503c_12f00f7e117__7ffb_00000007.tmp(系统找不到指定的路径) 在org.primefaces.webapp.MultipartRequest.parseRequest(MultipartRequest.java:67) 在org.primefaces.webapp.MultipartRequest。(MultipartRequest.java:49)
这是JSF的代码
<h:form enctype="multipart/form-data">
<!-- New Upload tool -->
<p:fileUpload fileUploadListener="#{uploadController.handleFileUpload}"
allowTypes="*.doc;*.docx;*.pdf;*.odt;" description="Text"/>
</h:form>
这是托管bean的代码的一部分
public void handleFileUpload(FileUploadEvent event) {
uploadedFile = event.getFile();
String fileName = FilenameUtils.getName(uploadedFile.getFileName());
String contentType = uploadedFile.getContentType();
byte[] bytes = uploadedFile.getContents();
Garbage garbage = new Garbage();
garbage.setFilename(fileName);
garbage.setFile(bytes);
garbage.setDescription("info about the file");
garbage.setFileType("File extension");
fileUploaderEJB.uploadGarbage(garbage);
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(String.format(
"File '%s' of type '%s' successfully uploaded!",
fileName, contentType)));
}
以防万一,这些主要内容与web.xml上的sutuff相关
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/uploaded</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
答案 0 :(得分:2)
\ uploaded \ upload_3be1503c_12f00f7e117__7ffb_00000007.tmp(系统找不到指定的路径)
缺少与安装Web服务器相同的根磁盘上的文件夹/uploaded
。创建它。