簡體   English   中英

JSF 2.2,帶有f:ajax的h:inputFile組件

[英]JSF 2.2, h:inputFile component with f:ajax

當我將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>

嘗試不使用f:ajax標簽嗎? 我在使用ajax時遇到這個標簽和錯誤消息的問題。 沒有ajax,一切都很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM