0
У меня есть страница jsp с кнопкой, эта ссылка на сервлет, и это создает PDF-файл потока, который как ответ.JSP Сервлет ответ pdf в JQuery
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
path = request.getServletContext().getRealPath("/");
String pdfFileName = "foo.pdf";
String contextPath = getServletContext().getRealPath(File.separator);
File pdfFile = new File(path + pdfFileName);
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=" + pdfFileName);
response.setContentLength((int) pdfFile.length());
FileInputStream fileInputStream = new FileInputStream(pdfFile);
OutputStream responseOutputStream = response.getOutputStream();
int bytes;
while ((bytes = fileInputStream.read()) != -1) {
responseOutputStream.write(bytes);
}
}
JQuery является
$(document).ready(function() {
$(".getpdfbutton").click(function(){
var currentRow=$(this).closest("tr");
var col1=currentRow.find("td:eq(0)").html();
var data3=col1;
alert(data3);
$.get("PDFerzeugen",{Spass:data3}, function(data) {
/* window.location = data; */
alert(data);
});
});
Я получаю RESPONS данных как base64, как я могу загрузить его в PDF-файл?
Возможный дубликат [Скачать файл с помощью JavaScript/JQuery] (http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery) – BackSlash
В чем проблема? Ваш pdf-файл не отображается или вы хотите его загрузить? – Mike
Посмотрите на это: [link] http://stackoverflow.com/questions/26332467/add-image-into-div-and-convert-base64-string-into-thumbnail-using-jquery [ссылка] – Vish