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

Inconsistency with Listeners

 
Trish Wu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For ServletContextListener's contextDestroyed(),
it is ok to get the attribute within this method through the event obj.
Whereas in HttpSessionListener's sessionDestroyed(). it will throw an IllegalStateException when trying to obtain the attribute from a session.
So does anyone know the rationale behind this inconsistency?
 
Bill Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the spec, sessionDestroyed(HttpSessionEvent se)Notification that a session was invalidated. This happens after session invalidation. When you tried to get a session attribute ref, you will get IllegalStateException.
While in ServletContextListener, contextDestroyed(ServletContextEvent sce)Notification that the servlet context is about to be shut down. This happens before the invalidation, so reference to any context attributes is still valid.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic