On Wed, 17 Jul 2002, Paul Phillips wrote:

> Date: Wed, 17 Jul 2002 19:20:00 -0500
> From: Paul Phillips <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: Tomcat Users List <[EMAIL PROTECTED]>
> Subject: io path information in servlets
>
> I have a webapp that stores some data in an xml file. (I am using jdom to
> read and write the xml files.)
>
> Right now I am using a construct like:
>
> String prefix = sc.getRealPath("/") + "/WEB-INF/dirName/";
>
> to get the path.  I then concatonate that with the file name and it works
> fine.
>
> However, in the javadocs for javax.servlet I read:
>
> "This method returns null if the servlet container cannot translate the
> virtual path to a real path for any reason (such as when the content is
> being made available from a .war archive)."
>
> I am not exactly sure what this means.  If I deploy this application as a
> .war, does the sc.getRealPath stop working?
>

Yes; assuming that Tomcat doesn't unpack the WAR into a directory, this
definitely stops working.  In that case, getRealPath() will return null
because there is no such thing as a "real path" to this resource path.

Note that the ability to run an application from an unpacked directory at
all is *not* a feature that the servlet spec requires -- the only
requirement is to accept a WAR.

If you want to do this kind of thing in a manner guaranteed to be
portable, you should make your servlet accept an initialization parameter
of some sort that identifies the directory in which output files should be
stored.

> Thanks
> Paul Phillips
>

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to