Solved

java variable for tomcat document root?

Posted on 2004-09-15
9
463 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default methods vs abstract class 1 118
iterator example remove 8 75
Is possible to make a jsp script work with oracle wallet? 7 104
iterator/ListIterator approach 17 39
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 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