Solved

java variable for tomcat document root?

Posted on 2004-09-15
9
466 Views
Last Modified: 2012-06-21
is there a java variable or method that can return tomcat's document root?
0
Comment
Question by:alskdj80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 12065415
TOMCAT_HOME ??
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 12065423
that's an environment variable
0
 
LVL 3

Author Comment

by:alskdj80
ID: 12065705
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!

 
LVL 27

Expert Comment

by:rrz
ID: 12066009
Try this. But, I hope someone has an easier way.
String path = getServletContext().getRealPath("/");
String tomcat =  path.substring(0,path.lastIndexOf(request.getContextPath()));    
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 12066034
I'm not sure whether you are looking for this or not.

some.jsp
======
<%
  String realPath = application.getRealPath("some.jsp");
%>
0
 
LVL 27

Accepted Solution

by:
rrz earned 250 total points
ID: 12066065
Or is it ?
String path = getServletContext().getRealPath("/");
String tomcat =  path.substring(0,path.lastIndexOf("/webapps"));    
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 12066169
this works for me:

String temp = System.getProperty("tomcat.home");
out.print(temp);
0
 
LVL 27

Expert Comment

by:rrz
ID: 12066210
Yes, bobbit's code is easier.
0
 
LVL 3

Author Comment

by:alskdj80
ID: 12066822
hmm, tomcat.home returns null for me...
but getServletContext().getRealPath("/"); return exactly what i wanted
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Why do some people recommend buying business VoIP from an ISP? What are the benefits to my company? What are the costs?
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question