Solved

java variable for tomcat document root?

Posted on 2004-09-15
9
455 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When Does RestAdapter establishes HttpConnection 5 199
immutable object concept 5 110
struts spring hibernate example 12 105
Books that can get me started on JAVA 2 76
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now