Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

webapp directory

Status
Not open for further replies.

dexter195

Programmer
Jun 18, 2003
220
EU
hi,

im using jsp and i need to create custom folders for people on my tomcat webserver inside the current webapp directory.

at the moment i have this hard coded which is a nusance as i need to change it depending on where its installed on each different machine.

is there a way to find what this is?

eg:- this is what it is on one machine

C:/Tomcat5/webapps/CompanysName/

but it could be installed as this by another user on another machine.

C:/Program Files/Tomcat 5.0.28/webapps/CompanysName/

thanks for the help
 
I would seriously avoid creating custome folders for "people" inside your webapp - if people need to save things in folders or something, then I would put them in a directory outside of your webapp.

--------------------------------------------------
Free Database Connection Pooling Software
 
we were doing that initially bacause of all the obvious concerns but it was causing problems that i can fix, but just dont have the time in the immidiate future and i just need a quick solution for a day or two.

the problem im having would seem to be applicable to either situation, wether we have the folders in the tomcat directory or elsewhere on the harddrive.

im thinking the easiest solution is to the have the reference to the storage folder path as a variable in the classpaths (which can be set when im setting up the server) and then just referencing that classpath in the jsp.

would this be a good way of going about this?

thanks for your help
 
You can get the root of your webapp like this :

Code:
// Either
//ServletContext sc = getServletConfig().getServletContext();
// Or
ServletContext sc = request.getSession().getServletContext();

String path = sc.getRealPath("/");

So in your example this would return the full path to your webapp :

C:/Program Files/Tomcat 5.0.28/webapps/CompanysName/
C:/Tomcat5/webapps/CompanysName/

--------------------------------------------------
Free Database Connection Pooling Software
 
excellent stuff.
that did the trick.

thanks a million for your help sedj :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top