This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes FileInputStream within a servlet - Path Question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "FileInputStream within a servlet - Path Question.." Watch "FileInputStream within a servlet - Path Question.." New topic

FileInputStream within a servlet - Path Question..

Brian Quinn
Ranch Hand

Joined: Dec 23, 2003
Posts: 32
I have a servlet within a web app, that loads a .xls file. I put the .xls file in the .war that contains the servlet, but I can not get the servlet to find the file . So my question is :
How do I use a relative path to find a file that is in a .war file from a servlet within that .war file ? Is it even possible ?
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
I think there are issues with getting the path from a war file. Normally I would use:
String realPath = application.getRealPath("/path/from/webroot/file.xsl");
This gives you the absolute file path; however, this used to not work when you had your app in a war file. I hardly ever deploy with a war file, so I am not sure of the solution (if the above does not work).
Hope this helps.

- Chris Stehno, SCPJ
I agree. Here's the link:
subject: FileInputStream within a servlet - Path Question..
It's not a secret anymore!