[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to change working directory in Tomcat

Posted on 2004-11-11
6
Medium Priority
?
514 Views
Last Modified: 2010-04-01
Hi all,

How to change working directory in Tomcat? Currently from my JSP I'm creating file and after that I'm finding this file in TOMCAT_HOME/bin, but I don't want to be there, I would like to be in my ROOT directory!
I know that I have to write something in web.xml or server.xml, but I don't know what exactly?!?!
Is there anybody that knows how to change my working directory?
Please write the lines that I have to add to this xml files in order to change my working directory!
Thanks in advance!
0
Comment
Question by:Valeri
  • 3
  • 2
6 Comments
 
LVL 16

Author Comment

by:Valeri
ID: 12553167
All that I need is to create this file in my Root directory. How to get the root directory and to create the file in this directory?
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 280 total points
ID: 12553205
try this:

String rootdir = getServletConfig().getServletContext().getRealPath("/");

use this directory to create the file
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 220 total points
ID: 12553207
<%
    String path = getServletContext().getRealPath( "." ) ;
    path = path.substring( 0, path.length() - 1 ) ;
    File f = new File( path + "file.zip" ) ;
%>

Should do it...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Expert Comment

by:TimYates
ID: 12553210
hehehe...  darn ;-)
0
 
LVL 16

Author Comment

by:Valeri
ID: 12612165
Only getServletContext().getRealPath( "." ) doesn't works...  "getServletConfig()" must be added in front. But what actually retruns this "getServletConfig()" ?!?!
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12612391
All JSPs are compiled into servlets, and getServletConfig() is a method of HttpServlet :-)

Hope it's all working!

Good luck!

Tim
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Last month Marc Laliberte, WatchGuard’s Senior Threat Analyst, contributed reviewed the three major email authentication anti-phishing technology standards: SPF, DKIM, and DMARC. Learn more in part 2 of the series originally posted in Cyber Defense …
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question