This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • 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.


Servlet is under:
JavSource Directory in WSAD in a package as -

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:
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.
Posts: 67340
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The context path is assumed.
[ February 07, 2006: Message edited by: Bear Bibeault ]
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!