aspose file tools
The moose likes Servlets and the fly likes Read PDF File Path From Servlet. PDF is right under WebContent Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Read PDF File Path From Servlet. PDF is right under WebContent" Watch "Read PDF File Path From Servlet. PDF is right under WebContent" New topic
Author

Read PDF File Path From Servlet. PDF is right under WebContent

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
What is the best way to read a PDF (or any file) from a Servlet?

PDF is sitting right under WebContent directory of a Web project. Please note that PDF is not inside WEB-INF.

WebContent:
myPdf.pdf

Servlet is under:
JavSource Directory in WSAD in a package as -
com.myCompany.myPackage.MyServlet

I want to get the path of the PDF file from Servlet and do file IO as:

File aFile = new File(filePathAndName);

I know the name of the file at runtime. So, I only need the file path within Servlet container.

I tried:
req.getContextPath()+"/myPdf.pdf" with no luck.

I also tried:
getServletContext().getRealPath("/myWebContext/myPdf.pdf")
No luck either.

What is the best way to get file path for the pdf from my servlet class?

My goal is to get a handle of the PDF file from Servlet. After I get a handle of the PDF file, I will get content of that PDF file.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56203
    
  13



The context path is assumed.
[ February 07, 2006: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read PDF File Path From Servlet. PDF is right under WebContent
 
Similar Threads
How to know the absolute directory path of WebContent folder?
Can't locate .js (or .css) files from a .jsp page.
Jboss-common-client.jar conflict
accessing a .properties file
Issues w/the PDFs and Back Buttons