Springmvc+ajaxfileupload upload picture ie browser bullet download box problem solution

Source: Internet
Author: User



Title, a simple record of the solution to the problem, the core cause of the problem is: Ajaxfileupload does not support the response header contenttype to Application/json settings, and IE does not support this format, The response type is automatically set to Application/json when we annotate with Springmvc @responsebody , so the workaround is to manually set the response type.


STEP1 Discard @responsebody, manually output the response through the stream, and specify a response type of text/html

@RequestMapping (value = "/fileimport2") public map<string, object> FileImport2 (HttpServletRequest request, HttpServletResponse response, Multiparthttpservletrequest req, @RequestParam ("filename") Multipartfile uploadfile) { Response.setcontenttype ("Text/html;charset=utf-8"); try {//File upload string Updateloadpath = Fileoperateutil.uploadexcel ( req, request,uploadfile); String Publishpath = Request.getsession (). Getservletcontext (). Getrealpath ("/");//... Slightly response.getwriter (). Write ("{\" data\ ": \" Ok\ "}");} catch (Exception e) {e.printstacktrace (); try {response.getwriter (). Write ("{\" data\ ": \" Error\ "}");} catch ( IOException E1) {//TODO auto-generated catch Blocke1.printstacktrace ();}} return null;}

STEP2 set the datatype of $.ajaxfileupload to text (otherwise the value of the callback function is [Object.object])

$.ajaxfileupload            (                {                    url:postpath+ "/app/studentscore/fileimport2",//server-side request address for file upload                    Secureuri: False,//whether a security protocol is required, general set to False                    Fileelementid: ' filename ',//File upload domain ID                    dataType: ' text ',//return value type generally set to JSON                    Success:function (data)  //server successfully responds to processing function                    {                     alert (data);                    var repobj = $.parsejson (data);                            if (Repobj.data = = ' OK ')                             {                                alert ("Import succeeded! ");                            }                             else                             {                                alert ("Data Exception!");}}            );

The problem is solved, and finally a simple look at the debug information of Firebug:



Springmvc+ajaxfileupload upload picture ie browser bullet download box problem solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.