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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring 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
Author

how to set an object in Application scope

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1162
    
    1

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

Joined: Jul 29, 2008
Posts: 3164
    
  47

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
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set an object in Application scope