2013-09-30 49 views
2

當我使用H:INPUTFILEF:AJAX,並嘗試將其部署到Apache的Tomcat的7.0.8, 以下異常被拋出在發送AJAX請求時由tomcat服務器發送。任何人都可以幫我解決這個問題。謝謝。在TomcatJSF 2.2,H:INPUTFILE組件與F:阿賈克斯

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

嘗試沒有F:AJAX標籤?使用ajax時,我遇到了這個標籤和錯誤消息的問題。沒有Ajax,每個人都很好。