aspose file tools
The moose likes Servlets and the fly likes how to set an object in Application scope Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "how to set an object in Application scope" Watch "how to set an object in Application scope" New topic
Author

how to set an object in Application scope

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 716

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 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
SCJP | SCWCD | OCA
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2729
    
    3

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 (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how to set an object in Application scope
 
Similar Threads
Storing InputStream object to Application scope in servlet and retrieving
How to specify an object in application scope
ServletContext and thread safe
Is jsp:useBean scope='session' attribute is going to be deprecated?
Sharing instances of a bean between JSP files