On Wed, 14 Mar 2001, Randy Layman wrote:

> 
>       The one major problem with what you ask is:  What happens if the
> application is run out of a WAR file?  As in, the JSP server does not expand
> the WAR to run it?  This is a possiblity according to the spec, although I
> don't know of any JSP environment that works in this way.
> 

FYI, Tomcat 4.0 can do this if you tell it to.

>       To set an Application's default directory, use
> System.setProperty("USER.DIR", "Path Here").  Be warned, however, that this
> will affect the default directory for every class that is running in the
> JVM, including Tomcat and any other webapps.  You probably don't want to do
> this.
> 

If your server is running under a security manager, you might not be
allowed to do this anyway.

>       You can use ServletContext.getRealPath("relative path") to get the
> address of some file in your webapp and then somehow mangle this if you need
> to write files that don't yet exist.  Be careful, though, because this might
> the be address to a file inside of a WAR file.
> 

There is no such thing as the "pathname" to an element inside the WAR
file.  In such a case, ServletContext.getRealPath() will return null.

>       If you only need to read files, you could use
> ClassLoader.getResource/getResourceAsStream or
> ServletContext.getResource/getResourceAsStream.  These methods find a file
> relative to your classpath (for ClassLoader) or webapp root (for
> ServletContext).  These methods only work for reading files that already
> exist.
> 
>       Another option is to store the path in a configuration file, like
> web.xml.  Accessing this depends on how you set it up.  A side not here,
> though, Tomcat only loads the web.xml file at the context load time (start
> in Tomcat 3, context load in Tomcat 4).  This means that you will have to
> force the Tomcat configuration to be loaded if you change the path.
> 

Such forcing is possible through the Admin application (Tomcat 3) or the
manager webapp (Tomcat 4).

>       The last option that I can think of right now is to hard code the
> path into your application.  This can either be relative to the startup
> directory (TOMCAT_HOME/bin) or an absolute path.  Both have downsides,
> relative to /bin makes you at the mercy of other applications that choose to
> mess with the USER.DIR propery (see first option) and the absolute path is
> almost always a bad idea.
> 
>       Randy
> 

Craig McClanahan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to