Link to home
Start Free TrialLog in
Avatar of alskdj80
alskdj80

asked on

java variable for tomcat document root?

is there a java variable or method that can return tomcat's document root?
Avatar of bobbit31
bobbit31
Flag of United States of America image

TOMCAT_HOME ??
that's an environment variable
Avatar of alskdj80
alskdj80

ASKER

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

some.jsp
======
<%
  String realPath = application.getRealPath("some.jsp");
%>
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this works for me:

String temp = System.getProperty("tomcat.home");
out.print(temp);
Yes, bobbit's code is easier.
hmm, tomcat.home returns null for me...
but getServletContext().getRealPath("/"); return exactly what i wanted