• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • 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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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