I'm trying to implement a workaround to the problem of using AJAX with multi-part form data. This page looks like a good idea. Bascially, instead of using AJAX you redirect the output of the form submission to an iframe. However, it isn't quite working for me. Here's my client-side HTML code:
<form id="submitDocumentForm" target='upload_target' name="submitDocumentForm" enctype="multipart/form-data" action="MyServlet" method="POST">
<input id="inputFile" type="file" name="inputFile"/>
<input type="submit" value="Import Document" />
<iframe id="upload_target" name="upload_target" src="" style="width:100;height:100;border:0px solid #fff;"></iframe>
</form>
The server side processing seems to work fine, but the client side response (IE7) is to pop up a File Download "Do you want to save this file, or find a program..." dialog box. Here's the relevant server side Java code:
//handling of the file and exception handling omitted
JSONObject responseData = new JSONObject();
responseData.put("messages", "Upload complete");
PrintWriter pw = response.getWriter();
response.setHeader(RESP_HEADER_CACHE_CONTROL, RESP_HEADER_VAL_NO_CACHE);
response.setContentType("application/json");
pw.println(responseData.toString());
pw.close();
Any suggestio开发者_高级运维ns as to how I might fix this? Many thanks in advance.
Set the response's Content-Type to text/plain
to force the browser to treat it as a document instead of a file.
精彩评论