This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes accessing web.xml from java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "accessing web.xml from java bean" Watch "accessing web.xml from java bean" New topic

accessing web.xml from java bean

Faris Syed

Joined: Jun 25, 2004
Posts: 8
Is it possible to read properties in web.xml file from a java bean?

I know from servlet we can get reference to ServletContext and from JSP pages we can do that by using application.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Yes you can do this. You want to use the "open the resource as steam" using the classloader's resources so it loads from the war instead of the filesystem. Check out the api docs for more information.

Faris Syed

Joined: Jun 25, 2004
Posts: 8
Thanks Nathaniel, for your reply.

I just added getServletcontext(ServletContext context) method in my bean so who ever uses the bean needs to pass the reference to a servlet context. And it works fine for me now.
I agree. Here's the link:
subject: accessing web.xml from java bean
jQuery in Action, 3rd edition