This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Regarding ServletContextListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding ServletContextListener" Watch "Regarding ServletContextListener" New topic

Regarding ServletContextListener

surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Friends,

why can't we put the code in servlet (in place of Listener i.e ServletContextListener) to initialize the application with database DataSource that all the servlets can use?

please correct me if I'm wrong.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60785

You can. You can also use a hammer to drive in a screw. But it's the wrong tool for the job. Servlets are meant to respond to requests, context listeners are meant to perform setup. Use the right tool for the job.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Regarding ServletContextListener
Similar Threads
Starting process threads when Tomcat starts
WA #1.....word association
Loading the Properties file in a Web Application
how-to call some servlet or bean when war is loaded
Can not compile filter