aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "file path in web container" Watch "file path in web container" New topic
Author

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:
..\tomcat5512\webapps\ROOT\html

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.

John
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

John,
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: file path in web container