• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The context path is assumed.
[ February 07, 2006: Message edited by: Bear Bibeault ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic