• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EPractice Lab quiz 3 about listener

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which of the events can be monitored by Java EE listeners?
[ Choose three ]

a.when a session is created
b.after a servlet is destroyed
c.when a session has timed out
d.when a cookie has been created
e.when a servlet has forwarded a request
f. when a session attribute value is changed

Choice A, Choice C and Choice F are correct
when a session is created - HttpSessionBindingListener
when a session has timed out - HttpSessionBindingListener
when a session attribute value is changed - HttpSessionAttributeListener
HttpSessionListener is used to receiving notification events about HttpSession lifecycle changes. It Receives notification that a session has been created. Receives notification that a session is about to be invalidated.
HttpSessionBindingListener - Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object. This may be as a result of a servlet programmer explicitly unbinding an attribute from a session, due to a session being invalidated, or due to a session timing out.
HttpSessionAttributeListener - This listener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application.


I think b is also an option. After a servlet is destroyed, the contextDestroyed method is called.


According to ServletContextListener API:

void contextDestroyed(ServletContextEvent sce)

Receives notification that the ServletContext is about to be shut down.

All servlets and filters will have been destroyed before any ServletContextListeners are notified of context destruction.

Parameters:
sce - the ServletContextEvent containing the ServletContext that is being destroyed


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think b is also an option. After a servlet is destroyed, the contextDestroyed method is called.

No, you won't get a notification if just one of the Servlets is destroyed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic