• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why they did so?

 
Max Bean
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I google for some good tutorials and then I see example of using the Servlet and ServletListener classes. I wonder why they place the same jobs in init(ServletConfig cfg) of the Servlet and in contextInitialized(ServletContextEvent event) of the ServletListener.

Wouldn't it be double jobs? Who's going to run first?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The context listener will execute when the server places the context (web app) into service. It will execute prior to the initialization of any servlet.

Initialization intended for the web application should be handled by the listener. Initialization specific to a servlet should be handled in the init() method of that servlet.
[ November 11, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!