2

当我将h:inputFilef:ajax一起使用并尝试将其部署在Apache-tomcat-7.0.8上时,当发送 AJAX 请求时,tomcat 服务器会引发以下异常。任何人都可以帮我解决这个问题。谢谢。

Tomcat 上的 javax.servlet.ServletException

com.sun.faces.renderkit.html_basic.FileRenderer decode
SEVERE: Unable to get parts for frmIndex:file
javax.servlet.ServletException: 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;charset=UTF-8

JSF 页面

<h:form id="frmIndex" enctype="multipart/form-data">

   <h:inputFile id="file" value="#{indexController.file}"/>

   <h:commandButton value="Upload" action="#{indexController.postTrailDetail}">
      <f:ajax execute=":frmIndex:tUpostPanelGroup" render="@all"/>
   </h:commandButton>

</h:form>

Java 控制器

@Component
@SessionScoped
@Scope("session")
@Qualifier("indexController")
public class IndexController implements Serializable {

  private Part file;

  public void postTrailDetail() {

   if(file != null) {} 

  }

  // Getter and Setter for Part

}

Maven 依赖项

       <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.0-m03</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.0-m03</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
4

1 回答 1

1

不带 f:ajax 标签试试?我在使用 ajax 时遇到了这个标签和错误消息的问题。没有ajax一切都很好。

于 2014-04-09T15:17:22.077 回答