JSF 2.2,h:带f:ajax的inputFile组件

时间:2013-09-30 08:09:41

标签: ajax tomcat7 jsf-2.2

当我将 h:inputFile f: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>

1 个答案:

答案 0 :(得分:1)

尝试不用f:ajax标签?使用ajax时,我遇到此标记和错误消息的问题。没有ajax,一切都很好。