This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX 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: 1341

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 8 Programmer I (1Z0-808), 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, CIW Certified Ecommerce specialist
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
Sheriff

Joined: Jul 29, 2008
Posts: 3697
    
  87

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
 
It's not a secret anymore!