You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Momper <ua...@gmail.com> on 2008/06/10 19:50:49 UTC

getRealPath() returning temp space path

In my application, I am trying to upload files to be stored in the
directory [application root]/files.  To get the path to write files
to, I am using:
request.getSession().getServletContext().getRealPath("/files");

However, this is returning the directory:
"apache-tomcat-6.0.16/temp/#-Application/files" where # is a number
0-9.
I thought it was supposed to return the path
"apache-tomcat-6.0.16/webapps/Application/files"

Am I gong about getting the path incorrectly, or do I need to change a
configuration somewhere in Tomcat?

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: getRealPath() returning temp space path

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Momper [mailto:uainne@gmail.com]
> Subject: getRealPath() returning temp space path
>
> However, this is returning the directory:
> "apache-tomcat-6.0.16/temp/#-Application/files" where #
> is a number 0-9.
> I thought it was supposed to return the path
> "apache-tomcat-6.0.16/webapps/Application/files"

It's not actually guaranteed to return anything; this is another shining example of why you should *never* use getRealPath() in a J2EE environment.

Tomcat provides a work area for webapps to use via the context attribute javax.servlet.context.tempdir; see the servlet spec and Tomcat configuration guide for details.

Alternatively, you could provide the desired location via an environment variable, system property, or JNDI value.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: getRealPath() returning temp space path

Posted by Mark Thomas <ma...@apache.org>.
David Momper wrote:
> In my application, I am trying to upload files to be stored in the
> directory [application root]/files.  To get the path to write files
> to, I am using:
> request.getSession().getServletContext().getRealPath("/files");
> 
> However, this is returning the directory:
> "apache-tomcat-6.0.16/temp/#-Application/files" where # is a number
> 0-9.
> I thought it was supposed to return the path
> "apache-tomcat-6.0.16/webapps/Application/files"
> 
> Am I gong about getting the path incorrectly, or do I need to change a
> configuration somewhere in Tomcat?

This is a result of using one of the anti-resource locking options in your 
context.

Mark


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org