File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to set an object in Application scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to set an object in Application scope" Watch "how to set an object in Application scope" New topic

how to set an object in Application scope

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1000

If I do not want to use caching mechanism, how can i access an object through the application life cycle?
I thought of adding an object in Application scope of web application but somehow not able to think from where should I start.
Please suggest how to add an object in Application scope.

I am using Tomcat 5.5 and my application is simple Servlet/JSP based (no Strust or Spring MVC etc)

~ abhay

Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

You could use ContextListeners for this.
Create your object and add it as a paramter to the context

Ashwin Sridhar
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885

Also, have a look at ServletContext class, which has a setAttribute(-) method to add, and getAttribute() method to get an object to/from the application scope.

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
I agree. Here's the link:
subject: how to set an object in Application scope
Similar Threads
ServletContext and thread safe
Is jsp:useBean scope='session' attribute is going to be deprecated?
How to specify an object in application scope
Storing InputStream object to Application scope in servlet and retrieving
Sharing instances of a bean between JSP files