Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Tomcat server root path  RSS feed

 
John McDonald
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
John McDonald
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got an exception when I tried to use this. It is access denial. Other approach? Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!