This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HeadFirst question about Listeners

 
Sue Pillai
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I am a Hf rookie and I was trying the mock exam at the end of chap 5 in the HF Servlets & JSP. Check out the question number 6. Pg 217.

I answered C,D thinking that the HttpSessionListener is in the javax.servlet.http package.

But the answer given is B, C & D.

Is there something wrong in my understanding of the question?

Please help. Thanks.

Sue
 
Sharika Raj
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't think deeply whether question is about Listeners in a package.
I have some doubts
One of the correct answer is C ServletContextListener can be used to perform an action when servlet context is about to be shutdown.

I am not able to understand this.I know there is a method contextDestroyed(..). I thought this will be called when context is detroyed, not before destroying.Can someone tell me what is correct.
 
Kedar Dravid
Ranch Hand
Posts: 333
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The contextInitialized method is called when the context is being initialised.
Similarly, the contextDestroyed method is called before the context is actually destroyed!
 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think contextInitialized is called after context is initialized and destroyed is called after it is destroyed, which doesn't help much but that's how it goes. Please correct me if i'm wrong.
 
Sue Pillai
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the API.

public void contextInitialized(ServletContextEvent sce)

Notification that the web application initialization process is starting. All ServletContextListeners are notified of context initialization before any filter or servlet in the web application is initialized.

contextDestroyed

public void contextDestroyed(ServletContextEvent sce)

Notification that the servlet context is about to be shut down. All servlets and filters have been destroy()ed before any ServletContextListeners are notified of context destruction.

But guys, the answer to my question??
 
Vineela Devi
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sue,

Yeah.Its a mistake in the HF Book.It should be
Which statements about the listeners are true
instead of
Which statements about the listeners defined in javax.servlet.package are true.
U can find tht at this:


Vineela
 
Sue Pillai
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vineela, that was a very useful link. I am passing it around in my friends circle.

May be JavaRanch can do that too for the HF users (if they haven't already)
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic