javax.servlet.ServletException the request doesn't contain a multipart/form-data or multipart/mixed stream

3k views Asked by At

I've the below form which uploads a file via <h:inputFile> and <f:ajax>.

<h:form enctype="multipart/form-data">
    <h:inputFile id="file" value="#{bean.file}" />
    <h:commandButton value="Upload" action="#{bean.upload}">
        <f:ajax execute="file" render="file" />
    </h:commandButton>
</h:form>

When I submit it, I get a JavaScript alert with the below error information:

serverError: class javax.servlet.ServletException 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

Is there any solution for this problem? I'm using Mojarra 2.2.11.

1

There are 1 answers

2
BalusC On BEST ANSWER

I reproduced it. It is a bug in Mojarra, introduced in 2.2.9 as side effect of the fix for issue 3129. Your problem is already reported as issue 3765. Basically: uploading files with ajax is broken since Mojarra 2.2.9 and there are no workarounds (at least not without hacking in the code).

For now, you need to downgrade to Mojarra 2.2.8 until they release the version with the fix.