Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I've created a program that upload PDF files from a server.
I save the uploaded file to
Java
getServletContext().getRealPath("/")+ "UploadedFiles\\";

Also I created a File Viewer to display the names of all uploaded files..
Now all I have to do is display the PDF file to browser.
My problem is the when I get the
Java
getServletContext().getRealPath("/")+ "UploadedFiles\\";

this is the value
D:\Java\Java Web Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PDFviewer\UploadedFiles\version.pdf
The path is not in my project location. Well I'm hoping I can do this to diplay the file
http://localhost:8080/PDFviewer/UploadedFiles/version.pdf

Can anybody give me an idea of displaying a PDF file?

My project location is
D:\Java\Java Web Projects\PDFviewer

REVISION:

Is there a way to get the Project Path
D:\Java\Java Web Projects\PDFviewer\WebContent\UploadedFiles\ instead of this
Java
getServletContext().getRealPath("/")+ "UploadedFiles\\";

D:\Java\Java Web Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PDFviewer\UploadedFiles\version.pdf

NOTE:
I can't do this C:\sample.pdf because I'm also running my web site to a client side computer, not in the server...
Posted
Updated 14-May-12 22:15pm
v4

You can use the Adobe JavaBean developed for this purpose. Please see the code sample here:
http://www.informit.com/guides/content.aspx?g=java&seqNum=377[^].

—SA
 
Share this answer
 
Comments
hansoctantan 15-May-12 7:24am    
Sorry but I think I can't use this code because I'm using a Web based Application...
Sergey Alexandrovich Kryukov 17-May-12 16:52pm    
I cannot get it: why cannot you use it. This is a JavaBean...
--SA
 
Share this answer
 
Comments
hansoctantan 15-May-12 7:22am    
I have try the http://www.mkyong.com/java/how-to-open-a-pdf-file-in-java/
but it only opens the pdf using the Adobe Reader.. All I want to do is open the pdf file within the browser...
hansoctantan 15-May-12 7:23am    
Also http://www.ehow.com/how_6103419_open-pdf-file-javascript.html this but it wont work...
I just posted a message http://www.codeproject.com/Messages/4252911/Re-Get-the-project-path-using-Java.aspx[^] in Web Developer discussion.

The problem is not the code. You can see the answer in above link
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900