Solved

java variable for tomcat document root?

Posted on 2004-09-15
9
459 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
  • 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
password protect pdf 11 76
method inner class 6 82
Struts tiles for layout structure along with Angular JS. 4 163
How to find missing packages when using Netbeans IDE 8.1 ? 19 54
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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