Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Servlets Code Examples

Servlet session event notifications

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
Servlet session event notifications package com.ack.web.servlet; import javax.servlet.http.HttpSessionActivationListener; import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionEvent; /** * Get application events for when a servlet session * is activated and destroyed. Also, get events when * attributes are added, removed and replaced within * the servlet session. <web-app> <listener> <listener-class>com.ack.web.servlet.ServletSessionEventNotifications</listener-class> </listener> </web-app> */ public class ServletSessionEventNotifications implements HttpSessionAttributeListener, HttpSessionActivationListener { public void sessionDidActivate( HttpSessionEvent evt ) { System.out.println( "session activated: " + evt ); } public void sessionWillPassivate( HttpSessionEvent evt ) { System.out.println( "session passivated: " + evt ); } public void attributeAdded( HttpSessionBindingEvent evt ) { System.out.println( "attribute added to session: " + dump( evt ) ); } public void attributeRemoved( HttpSessionBindingEvent evt ) { System.out.println( "attribute removed from session: " + dump( evt ) ); } public void attributeReplaced( HttpSessionBindingEvent evt ) { System.out.println( "attribute replaced in session: " + dump( evt ) ); } private String dump( HttpSessionBindingEvent evt ) { return "\n attribute name: " + evt.getName() + "\n session: " + evt.getSession() + "\n attribute value: " + evt.getValue(); } }