Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

java variable for tomcat document root?

is there a java variable or method that can return tomcat's document root?
0
alskdj80
Asked:
alskdj80
  • 3
  • 3
  • 2
  • +1
1 Solution
 
bobbit31Commented:
TOMCAT_HOME ??
0
 
bobbit31Commented:
that's an environment variable
0
 
alskdj80Author Commented:
hmm, how would i get that variable in a servlet?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
rrzCommented:
Or is it ?
String path = getServletContext().getRealPath("/");
String tomcat =  path.substring(0,path.lastIndexOf("/webapps"));    
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now