Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets" Watch "servlets" New topic
Author

servlets

arunas rao
Greenhorn

Joined: Jun 28, 2005
Posts: 5
How does the application object(servlet context) is accessed from any where
in the web application? what is the role of application.getAttribute(" ") method in this?
Johnson Abraham
Greenhorn

Joined: May 31, 2004
Posts: 19
Application container can be accessed in this fashion

javax.servlet.ServletContext context = getServletContext();

now context is your application object.

You can use the following line of code to store any object at the application level:

context.setAttribute("myObject",myApplicationObject);

Now if you want to retrieve the object from the application scope you can use the following line of code:

MyApplicationObject myApplicationObject = (MyApplicationObject) context.getAttribute("myObject");

Johnson
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: servlets
 
Similar Threads
Tech Word Game
adding tomcat 6.0 error
StuckThreadMaxTime Error.
single threaded or multi threaded
Deploy Java Application On Customer Side?