wood burning stoves*
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets