如何从servlet发送PDF文件(OutputStream)到ajax响应在浏览器中打开?

时间:2015-01-29 12:14:15

标签: java ajax servlets dynamic-reports

我正在使用ajax向我的servlet发送请求以生成报告。

报告已生成但我想在浏览器中显示

这是我的请求的ajax代码

$.post('servleturl',{
            from : from,
            to : to
        },function(data){
            // What should I write here in order to display report in browser

        });

我的servlet代码

OutputStream outputstream = response.getOutputStream();

//This line converts the report to PDF
report.toPdf(outputstream);
outputstream.close();

//Converting the outputstream to JSON to pass as response

                    json = new Gson().toJson(outputstream);            
                    response.setContentType("application/json");
                    response.getWriter().write(json);

0 个答案:

没有答案