从servlet检索文件时,Jquery Ajax解析错误

时间:2014-08-26 03:17:08

标签: java jquery ajax servlets pdf

我在服务器端创建PDF文件,并在servlet请求时返回此文件。我正在使用jquery ajax调用检索这个,但是是在给我解析错误,可能是什么原因?

服务器端代码

response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("application/pdf");
String fileName = "Vendormaster.pdf";
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName  + "\"");
RandomAccessFile f = new RandomAccessFile("D:/PDF_1.pdf", "r");
byte[] pdfBytes= new byte[(int)f.length()];
f.read(pdfBytes);
ServletOutputStream out = response.getOutputStream();
response.setContentLength(pdfBytes.length);
out.write(pdfBytes);
out.flush();

调用Ajax

function GetData(url){  var dataObject=[];  $.ajax({

        url : url,
        type : "GET",
        async : false,
        dataType : 'json',
        contentType : "application/json",
        beforeSend:function(){ //           $("#ajaxloader").fadeIn();      },
        success : function(data, textStatus, jqXHR) {        dataObject= data; //        $("#ajaxloader").fadeOut(0);

        },
        error : function(data,b,c) {
            var error; //           $("#ajaxloader").fadeOut(0);
                return null;
        }

来自Live Http标题的标题

  

GET / vendor_master_new / PdfGen HTTP / 1.1主机:xx.xx.xxx.xx:50000   接受:application / json,text / javascript, / ; Q = 0.01   Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en; q = 0.8   Content-Type:application / json Cookie:saplb _ * =(J2EE3952620)3952650;   MYSAPSSO2 = AjExMDAgABRwb3J0YWw6QWRtaW5pc3RyYXRvcogAB2RlZmF1bHQBAAACAAMwMDADAANFUDEEAAwyMDE0MDgyNjAyNDEFAAQAAAAICgAA%2FwEEMIIBAAYJKoZIhvcNAQcCoIHyMIHvAgEBMQswCQYFKw4DAhoFADALBgkqhkiG9w0BBwExgc8wgcwCAQEwIjAdMQwwCgYDVQQDEwNFUDExDTALBgNVBAsTBEoyRUUCAQAwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTE0MDgyNjAyNDEyMFowIwYJKoZIhvcNAQkEMRYEFNI0asgM56O%2FhRIw9maLcMVSFKjLMAkGByqGSM44BAMELjAsAhRVFdOnzxSD1X6 YYuN3rFTWD4QGwIUa6cOuiyvPzHS355ksX7%2Ft5az3c%3D;!   JSESSIONID = olcptllrixgcMgn5_xL0y4mRZzAQSAEKUDwA_SAP-1UuLDj55yIZYsgUl10Rvcmd;   JSESSIONMARKID = ccttaAveOF7gPQfOE5gGjfKliPgTAVLdbcRwpQPAA Referer:   http://xx.xx.xxx.xx:50000/vendor_master_new/vendorMaster.html   User-Agent:Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36   (KHTML,与Gecko一样)Chrome / 36.0.1985.143 Safari / 537.36   X-Requested-With:XMLHttpRequest

     

HTTP / 1.1 200 OK内容配置:附件;   filename =“Vendormaster.pdf”content-length:480288 content-type:   application / pdf date:Tue,26 Aug 2014 03:10:54 GMT expires:Thu,01   1970年1月00:00:00 GMT编译指示:无缓存服务器:SAP NetWeaver   Application Server 7.41 / AS Java 7.40

0 个答案:

没有答案