This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes init options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "init options" Watch "init options" New topic

init options

Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37

In my app there are more then 3 servlets. And I need to call something like the init() method to config somethings.

But I think the init is only for its servlet, how can I do some init like so that all servlets can use the things I will start in it?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60765

Research the concept of a context listener.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Devika Narasimhaiah

Joined: Oct 24, 2008
Posts: 2

First write a Listener class which implements ServletContextListener. and
use setAttribute(var,val) and this attribute you can use in all servlets.

otherwise, use context-param tags in web.xml

That also works same.

It is sorta covered in the JavaRanch Style Guide.
subject: init options
Similar Threads
init and constructor in servlet
How to obtain hostname during servlet init
JSF + Hibernate - startup
init() and init(conf)
question on implicit objects in EL?