• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Application Root

 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I wanted to store a file in the root directory of current web application
When I am creating a file it stored in Tomcat5.5 Home directory
When I tried with eclipse it was stored in Eclipse Home
I need a way to get the Context home so that I need not change the code later.

-Prabhakar
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your application is running from an exploded file system (as opposed to a packed war archive), you can use the context.getRealPath("/") method.
java.lang.String)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's fine in Servlets
But how can I get a Context in the ServletContextListener.
I want to read a file while the application starts.
-Prabhakar
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey sorry
I got the context from ServletContextListener.
Thanks for your post.
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prabhakar Rao:
Hey sorry
I got the context from ServletContextListener.
Thanks for your post.


request.getContextPath() gives the root of the current Context i.e root of the current web application.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vishwanath nadimpally:


request.getContextPath() gives the root of the current Context i.e root of the current web application.

Requests don't ever get passed to contextListeners.
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:

Requests don't ever get passed to contextListeners.


I didn't mean from the context listeners. I just said request.getContextPath() is a way to get the context.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vishwanath nadimpally:


I didn't mean from the context listeners. I just said request.getContextPath() is a way to get the context.


Right, but the original poster was looking for a way to get it from a context listener:

That's fine in Servlets
But how can I get a Context in the ServletContextListener.
I want to read a file while the application starts.
-Prabhakar
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
[QB][/QB]


my bad!
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all
I found the solution for this post.
Please suggest a solution for my other post regarding Response headers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic