This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
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");

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?