tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Servlet WAR file and path names
Date Fri, 07 Apr 2000 06:52:33 GMT
Jason Hunter wrote:

> > > Does Tomcat have a way to give names to non-JSP and servlet
> > > resources, or to report the path location of a servlet's web
> > > application location?
> > > Otherwise, it makes including additional support files very
> > > difficult.  Any help or suggestions would be appreciated!
> > >
> >
> > The convention recommended in the servlet specification is to use
> > ServletContext.getResource() or ServletContext.getResourceAsStream()
> > to access things like this, rather than doing file i/o.  That way,
> > your web app will still work even in an advanced servlet container
> > that does not run out of the filesystem.
> >
> > The conventional place to store things like this is in the WEB-INF
> > directory.
> > So if you stored such a file at:
> >
> >     WEB-INF/mystylesheet.xsl
> >
> > you could access it in a servlet (or JSP page) like this:
> >
> >     InputStream stream =
> > getServletContext().getResource("/WEB-INF/mystylesheet.xsl");
> Now the $64,000 question is: What can you do to have the servlet make
> a *change* to the configuration file under WEB-INF?  The default "file:"
> URL in Tomcat doesn't support "output", nor would URL even have a good
> API for writing.  Seems to me we have a read-only solution.  There's no
> good place to store a webapp's long-term writable files.

There's no "write" access on getResourceAsStream(), so the question stands,
although there's no restriction on a particular URL returned by getResource()
supporting write access (that's what an HTTP PUT normally does, after all).

For short term temporary use, a servlet container is required to provide the object pointing to a writeable directory, under context attribute
"javax.servlet.context.tempdir" (Servlet API Specification, version 2.2,
section 4.7).  For long term storage, the current recommendation is to use
databases, directory servers, EJBs, or some other resource that is accessible
from a servlet based application.  It's not obvious that the servlet API
itself needs to provide this facility, given the other options available.

> -jh-

Craig McClanahan

View raw message