天天看點

IE中使用ajaxSubmit上傳檔案彈出下載下傳提示框

IE中使用ajaxSubmit上傳檔案彈出下載下傳提示框

 頁面代碼:

IE中使用ajaxSubmit上傳檔案彈出下載下傳提示框

var options = {  

               url: "<%=path%>/upload/upload",  

               type: "post",  

               datatype:'html',  

               success:function(json) {  

                   alert("json:"+json);  

 },  

               error:function(er){  

                   alert("er:"+er);  

                   //functionchange(er.responsetext);  

               }  

    };  

        $('#picform').ajaxsubmit(options);  

 背景代碼:

IE中使用ajaxSubmit上傳檔案彈出下載下傳提示框

/*** 

     * {"filename":"20141002125209_571slide4.jpg","path":"d:\\software\\eclipse\\workspace2\\demo_channel_terminal\\upload\\image\\20141002125209_571slide4.jpg"} 

     * @param file 

     * @param request 

     * @param response 

     * @return 

     * @throws ioexception 

     */  

    @responsebody  

    @requestmapping(value = "/upload")  

    public modelandview upload(  

            @requestparam(value = "image223", required = false) multipartfile file,  

            httpservletrequest request, httpservletresponse response)  

            throws ioexception {  

        map map = new hashmap();  

        if (valuewidget.isnullorempty(file)) {  

            map.put("error", "not specify file!!!");  

        } else {  

            system.out.println("request:" + request);// org.springframework.web.multipart.support.defaultmultiparthttpservletrequest@7063d827  

            system.out.println("request:" + request.getclass().getsuperclass());  

            // string formfiletagname=null;//"file2"  

            // for( ;multi.hasmoreelements();){  

            // string element=multi.nextelement();  

            // formfiletagname=element;//表單中标簽的名稱:file标簽的名稱  

            // // system.out.println("a:"+element+":$$");  

            // break;  

            // }  

            string filename = file.getoriginalfilename();// 上傳的檔案名  

            filename=filename.replaceall("[\\s]",   "");//ie中識别不了有空格的json  

            // 儲存到哪兒  

            string finalfilename = timehwutil.formatdatebypattern(timehwutil  

                    .getcurrenttimestamp(),"yyyymmddhhmmss")+ "_"  

                            + new random().nextint(1000) + filename;  

            file savedfile = getuploadedfilepath(request,  

                    constant2.upload_folder_name + "/image", finalfilename,  

                    constant2.src_main_webapp);// "d:\\software\\eclipse\\workspace2\\demo_channel_terminal\\ upload\\pic\\ys4-1.jpg"  

            system.out.println("[upload]savedfile:"  

                    + savedfile.getabsolutepath());  

            // 儲存  

            try {  

                file.transferto(savedfile);  

            } catch (exception e) {  

                e.printstacktrace();  

            }  

            map.put("filename", filename);  

            map.put("path", savedfile.getabsolutepath());  

            system.out.println("map:"+map);  

        }  

        modelandview modelandview = new modelandview(  

                new mappingjacksonjsonview(), map);  

/* 

 * {"filename":"20141002125209_571slide4.jpg","path":"d:\\software\\eclipse\\workspace2\\demo_channel_terminal\\upload\\image\\20141002125209_571slide4.jpg"} 

 * */  

        return modelandview;  

    }  

 解決方法:讓action傳回string,而不是modelandview.

修改後的action:

IE中使用ajaxSubmit上傳檔案彈出下載下傳提示框

    public string upload(  

        string content = null;  

            objectmapper mapper = new objectmapper();  

            map.put("filename", "a");  

                content = mapper.writevalueasstring(map);  

                system.out.println(content);  

            } catch (jsongenerationexception e) {  

            } catch (jsonmappingexception e) {  

            } catch (ioexception e) {  

//      modelandview modelandview = new modelandview(  

//              new mappingjacksonjsonview(), map);  

        return content;  

參考:http://www.kankanews.com/ickengine/archives/42240.shtml

http://www.yunmasoft.com/