java variable for tomcat document root?

is there a java variable or method that can return tomcat's document root?
LVL 3
alskdj80Asked:
Who is Participating?
 
rrzCommented:
Or is it ?
String path = getServletContext().getRealPath("/");
String tomcat =  path.substring(0,path.lastIndexOf("/webapps"));    
0
 
bobbit31Commented:
TOMCAT_HOME ??
0
 
bobbit31Commented:
that's an environment variable
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
alskdj80Author Commented:
hmm, how would i get that variable in a servlet?
0
 
rrzCommented:
Try this. But, I hope someone has an easier way.
String path = getServletContext().getRealPath("/");
String tomcat =  path.substring(0,path.lastIndexOf(request.getContextPath()));    
0
 
sompol_kiatkamolchaiCommented:
I'm not sure whether you are looking for this or not.

some.jsp
======
<%
  String realPath = application.getRealPath("some.jsp");
%>
0
 
bobbit31Commented:
this works for me:

String temp = System.getProperty("tomcat.home");
out.print(temp);
0
 
rrzCommented:
Yes, bobbit's code is easier.
0
 
alskdj80Author Commented:
hmm, tomcat.home returns null for me...
but getServletContext().getRealPath("/"); return exactly what i wanted
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.