Solved

java variable for tomcat document root?

Posted on 2004-09-15
9
465 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
Independent Software Vendors: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lamba in java 8 9 261
How to group array of objects ? 5 79
using if condition without JSTL 2 119
How to find missing packages when using Netbeans IDE 8.1 ? 19 85
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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