This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "accessing web.xml from java bean" Watch "accessing web.xml from java bean" New topic
Author

accessing web.xml from java bean

Faris Syed
Greenhorn

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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Faris Syed
Greenhorn

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.
 
 
subject: accessing web.xml from java bean