Question

I have a Following JSP:

            <form action="UploadServlet" method="post" enctype="multipart/form-data">
         Select file to upload: <input type="file" name="file" id =upfile"size="50" /> <input type="button" value="Save" onclick="javascript:uploadPartnerDetails();" class="buttons">
            </form>

And DWR Script which calls remoted Java Method:

  function uploadPartnerDetails() {
  SMUDWR.uploadPartnerDetails(function(data) {
    dwr.util.setValue("UserTypeDiv", data, {
        escapeHtml: false
    });

});
}

The Remoted Method uploadPartnerDetails()is:

try {
        WebContext wctx = WebContextFactory.get();
       HttpServletRequest request = wctx.getHttpServletRequest();

        // checks if the request actually contains upload file
        if (!ServletFileUpload.isMultipartContent(request)) {
            // if not, we stop here

        }

I get This Error :

the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header is text/plain

The Problem is the request above does not contain multipart/form-data. How to I get that from this request?

Was it helpful?

Solution

In general DWR calls are AJAX calls and in AJAX we cannot upload files just like form data. There are different ways to upload files using AJAX calls

Find different ways provided in answers to this question jQuery Ajax File Upload

Go through these and you will get better understanding of file handling with AJAX

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top