File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes file path in web container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "file path in web container" Watch "file path in web container" New topic

file path in web container

John McDonald
Ranch Hand

Joined: Jul 01, 2003
Posts: 112
Hi there, I would like to deposit a dynamic generated page for subsequent calls. But I don't know how to set a path for it. As you know, that the general path for web container as follow:

If my servlet generates a.html, b.html under above directory, how do I set the path relative to that directory?

I don't want to has java code to pick up by environment variable. and my servlet package is a.b.c because I want to turn this servlet to bean in phrase 2. Thank you very much.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

One thing to keep in mind.
Java webapps aren't always deployed as a file system directory.
When they are, you can get the system path to any resource within your application using java.lang.String)" target="_blank" rel="nofollow">ServletContext.getRealPath

If your webapp is deployed as a packed war file this method will return null.

A more robust way of doing this is to use context init params or servlet init params that are configured in web.xml.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: file path in web container
It's not a secret anymore!