By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

How to write a file in the directory of a webapp..

P: n/a
SPG
Hi,
I have a servlet application running on tomcat.
I want to write a default config file in the root directory of the
application:

tomcat
+webapps
+myapp
+myConfig.txt

If I use new File(./myConfig.txt), then the file goes to the root of tomcat.
Ither there an easy way to find out the directory of the running app?

Cheers,

Steve
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I've got the same issue... the only work-around i found was to specify the
entire path to the file in the web.xml file as an initialization parameter
to a servlet. That obviously doesn't work for .WAR deployments, though.
Anyone else have a better solution? I'd love to hear it.

Jeff

"SPG" <st************@nopoo.blueyonder.co.uk> wrote in message
news:JK*********************@news-text.cableinet.net...
Hi,
I have a servlet application running on tomcat.
I want to write a default config file in the root directory of the
application:

tomcat
+webapps
+myapp
+myConfig.txt

If I use new File(./myConfig.txt), then the file goes to the root of tomcat. Ither there an easy way to find out the directory of the running app?

Cheers,

Steve

Jul 17 '05 #2

P: n/a
>
Ither there an easy way to find out the directory of the running app?

Try this one -if the WAR file is expandend

getServletContext().getRealPath("/");
Lau.
Jul 17 '05 #3

P: n/a
DWY
I have a similar question in that I have a .war deployed and allow users
to upload to a folder named WEB-INF/uploads. However, how can I retain
what they uploaded if I need to re-deploy the .war?

The app. server creates a new folder when deploying a .war, meaning, the
path changes and the files previously uploaded are now not in the
WEB-INF/uploads folder.

Pipo wrote:
Ither there an easy way to find out the directory of the running app?

Try this one -if the WAR file is expandend

getServletContext().getRealPath("/");
Lau.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.