Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Life-cycle Events for Servlets

 
Naresh Gangapur
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this question in one of the mock exams (Java Beat)..

Which of the following life-cycle Events are available as part of Servlets?

a. Initialization of Servlet's ServletContext object.
b. Destruction of Servlet's ServletConfig object.
c. Initialization of Servlet's HttpSession object.
d. Destruction of Servlet's HttpServletRequest object.

Answer mentioned - b and d.
Construction and Destruction of Servlet Config object is not defined in the Java Servlets
Specification, same is the case with Servlet's Request object.

I am not sure if there is a typo-error on this.
Well, I would think none of the otions would go. Only construction of the ServletConfig could be part of the life cycle event, which could be close to, based on the options that are listed above.

Please advise.
 
anu sav
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think , destruction happens in servlet life cycle's destroy() method. which is called only once like init().
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is not clear. I would say that none of these are part of any class/event in the Servlet API, since object construction, initialization and destruction are up to the JVM. Constructing an HttpSession object is not the same as creating an HTTP session - for that, other things have to happen. And removing an HTTP session is not the same as destructing an HttpSession object (which may happen a good deal later, whenever it pleases the JVM).

If one were to disregard this point, I'd say "a" is possible through ServletContextListener.contextInitialized, and "c" is possible through HttpSessionListener.sessionCreated.
 
Naresh Gangapur
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if there were to be an option -

"Initialization of Servlet's ServletConfig object" -

I would think this would be a correct answer.
Part of the init method would be to set the servlet init params in the DD to the servlet config object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic