Java – how to open PDF in a new tab and display it in the browser (no download required)?
•
Java
I have a PDF link. When I click it, I want it to open a new tab and render it in the new tab, instead of asking me to download it What do I do?
Please note that I ask this question, so I can answer it This information can be pieced together from other answers, but I hope it can be in one place
Solution
To open a link (PDF or not PDF) in a new tag, you must modify the HTML of the link
<a href="javascript:void()" class="outlink" data="/link_to_pdf.pdf">PDF</a>
to
<a href="javascript:void()" class="outlink" data="/link_to_pdf.pdf" target="_blank">PDF</a>
To open a PDF in a browser, you must change the server side to the response header In Java, you do this:
response.setContentType("application/pdf"); response.addheader("content-disposition","inline; filename=link_to_pdf.pdf");
The most important thing is inline If you place an attachment, your browser will try to download it@ L_ 404_ 1@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码