It's not a secret anymore!
The moose likes Servlets and the fly likes Need to know the path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need to know the path" Watch "Need to know the path" New topic

Need to know the path

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi All,
We are keeping our some static contents on webserver (IHS). and in my java/action file if I want that path what should I do?
I want to know the webserver path.
I tried with contextpath it is giving me appl.server.

Please help me

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You want to get an absolute file system path based on the relative web context path?
If so, you can use ServletContext#getRealPath() for that. Also see the API docs.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If I understand the question correctly, this file is not within the web application's context. It's being served by the web server which sits between the application server and the network. Presumably the two servers are on the same machine, which is why sreedhar thinks this question should have an answer. If they were on different machines, then clearly it wouldn't have an answer, and that suggests to me that there's nothing in the Servlet API which will produce the path.

If it were me I would go back and look for a solution to the unstated problem which didn't require knowing that path. Or I would hard-code the path as an application parameter.
I agree. Here's the link:
subject: Need to know the path
It's not a secret anymore!