vineeth Prabhakaran vineeth Prabhakaran - 1 year ago 83
Java Question

How to display PDF file in browser

In my servlet I am using the code below to open a PDF file in a browser, but instead, it shows a download dialog box.

What I am doing wrong?

out = response.getWriter();
String filepath = "D:/MyFolder/PDF/MyFile.pdf";

response.setHeader("Content-Disposition", "inline; filename=" + filepath + ";");
FileOutputStream fileOut = new FileOutputStream("D:/MyFolder/PDF/MyFile.pdf");


Answer Source

u can try to do the same with

response.setHeader("Content-Disposition", "attachment; ilename="+filepath+";");