This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Setting application attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Setting application attribute" Watch "Setting application attribute" New topic
Author

Setting application attribute

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Hi Friends,

I need to set some application attribute in the very beginning whenever tomcat is being restarted.

Where should i put the code to be executed???

somthing like:



any ideas?

Thanks, Joseph


We must know, we will know. -- David Hilbert
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

That's what context listeners are for:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContextListener.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nikhilesh Fonseca
Ranch Hand

Joined: Aug 23, 2004
Posts: 57
You can put that application scope variable
on init method of oyur controller servlet.That is the sevlet ewhich load on start up as 1.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56183
    
  13

Prior to the advent of context listeners, a load-on-startup servlet was frequently used to perform application-wide initialization, but a context listener is a much better way to do it now that they are available.

It is guarenteed that all context listeners are executed before any servlets are loaded or executed.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Setting application attribute
 
Similar Threads
contextScope attribute setting
How to allow null to an object attribute?
JMS on jboss consumer rate limit and producer rate limit
jboss, datasource naming and lookup error
HttpSessionAttributeListener Not Working