This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file path in web container
 
Similar Threads
File IO using JSPs & Tomcat
How to define a local TLD in web.xml?
integrating a web application with a database
create file in servlet
using log4j in servlets