Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Getting Application Root

 
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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.
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.
 
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 VI Editor Redhat
  • 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 VI Editor Redhat
  • 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!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
 
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.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic