Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init options

 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Research the concept of a context listener.
 
Devika Narasimhaiah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI...

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.


Regards
Devika.N
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic