This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes ServleContext In Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServleContext In Beans" Watch "ServleContext In Beans" New topic
Author

ServleContext In Beans

Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
I have create an Object and Placed in the context using "getServletContext().setAttribute("x", xyz)" in a servlet. Now I want to access the same from the servlet context in a bean/class. How it can be done?
Thanks
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
The only way to do it is to pass the servlet context object to your class. You could pass it in in the constructor and hold onto it for the lifetime of the instance, or pass it in through another method.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
Consider Paul's rocket mass heater.
 
subject: ServleContext In Beans