我尝试使用简单的fileuploader上传文件,但我一直收到此错误:
org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>40960</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/home/alen/uploads</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bootstrap</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>
</web-app>
XHTML:
<h:form enctype="multipart/form-data">
<h:panelGrid columns="1" style="width:100%;" class="imageUploadTable">
<p:fileUpload value="#{objave.file}" mode="simple"/>
<f:facet name="footer">
<p:commandButton actionListener="#{objave.spremiSliku()}"
value="Spremi"
icon="ui-icon-disk"
ajax="false"/>
</f:facet>
</h:panelGrid>
</h:form>
Objave.java
private UploadedFile file;
public String spremiSliku() {
System.out.println(file.getFileName());
return "";
}
如果我使用高级fileUploader,那么一切正常,但我需要简单的fileUploader,并且无法使其工作。我是PrimeFaces菜鸟,所以我不知道如何解决这个问题。有人可以帮我这个吗?