File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


arunas rao

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

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:


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");

I agree. Here's the link:
subject: servlets
It's not a secret anymore!