special
special

Reputation: 641

Opening a Local PDF file in Browser using JSP

I have tried to open a PDF file from the local disk.

For example the Location is:

E:/files/IT/cat1/cat1Notification.pdf

But during runtime the link changes to:

http://localhost:8080/Office_Automation/E:/files/IT/cat1/cat1Notification.pdf

How to do i get rid of http://localhost:8080/Office_Automation/ from the link and open the file?

I have used

<a href="<%=path%>">click here</a>

Upvotes: 2

Views: 9816

Answers (1)

reevesy
reevesy

Reputation: 3472

To open the local file you need to use the file scheme in your URL

As you path is a Windows path E:/files/IT/cat1/cat1Notification.pdf, the link's href needs file:/// added before the your jsp's <%=path%> variable, so that the browser knows it needs to open a local file on the user's machine.

So your link should look like this

<a href="file:///<%=path%>">click here</a>

Which in your browser will resolve to file:///E:/files/IT/cat1/cat1Notification.pdf

Without the file scheme the browser assumes that your link is relative to the webpage and tries to resolve the link by making a request to your webapp. This is why you were getting http://localhost:8080/Office_Automation/E:/files/IT/cat1/cat1Notification.pdf

Upvotes: 1

Related Questions