How do I open a PDF document from JSP? I have many links to PDF files. In Eclipse, when I click on the link, the PDF opens in PDF reader. But in a webbrowser like Firefox and Chrome, nothing happens.
I am generating the links to PDF files as F:\....\...pdf the following way:
<%
while (iter.hasNext()) {
element = iter.next();
bookName = getBookName(element);
%>
<ul>
<li><a href="<%=element %>"><%=bookName %></a>
</ul>
<%
}
%>
How is this problem caused and how can I solve it?
The links have to point to an URL, not to a local disk file system path or something. The average webbrowser doesn’t swallow this due to security restrictions. And even then when it did, it would not work in production environment when the webbrowser runs at a physically different machine than the webserver and thus doesn’t have access to
F:disk at all.So, you should NOT use
but you should rather use
or when it’s for example in the same folder of the current JSP file
If you cannot put the PDF file in your own web project, then you need to look for different solutions.
You can find the above solutions in detail in the answers of the following questions: