• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing web.xml from java bean

 
Faris Syed
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic