File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Tomcat server root path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat server root path" Watch "Tomcat server root path" New topic
Author

Tomcat server root path

John McDonald
Ranch Hand

Joined: Jul 01, 2003
Posts: 112
Hi there,
How do I find out a path of server root from servlet, or current location of the running servlet? Thanks.

John
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62276
    
  68

Originally posted by John McDonald:

How do I find out a path of server root from servlet


servletContext.getRealPath( "/" );

Only works when the app is not being run out of an unexpanded war file.

Originally posted by John McDonald:

or current location of the running servlet?


I don't know what that means. The location of the class file? Other than that (which is not useful info generally), servlets don't really have the concept of a "location".
[ March 20, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John McDonald
Ranch Hand

Joined: Jul 01, 2003
Posts: 112
I got an exception when I tried to use this. It is access denial. Other approach? Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62276
    
  68

Then you have an issue with your setup. Trying "another approach" because the supported method isn't working due to a setup problem isn't the best course of action.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62276
    
  68

Or, are you running the app out of an unexpanded war file?

If not, you're probably having a file system permissions issue that will need to be resolved.
John McDonald
Ranch Hand

Joined: Jul 01, 2003
Posts: 112
Thanks for all the input. Yes, I tried to dynamically generate a some html file at the root of my war file. Say


Tomcat\bin
\conf
\webapps\generator.war
generator\WEB-INF\classes\package\servlet.class


I need to generate a html file so that I can access throught the browser as
http://mydomain/generator/html/new_html.html file.

How do I acquire the physical path from the servlet so that I can gernate such html file? Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62276
    
  68

I already told you how to do it. If you are having a permissions problem with the file system that is something you are going to have to straighten out with the system admin for the server.
 
Don't get me started about those stupid light bulbs.
 
subject: Tomcat server root path