java - Session start event handler in jsp -


in asp.net, have global.asax, have session_start method, runs when new user first visit. similar thing in jsp?

i got advice can use intercepter, still confuse that, how intercepter capture session_start

use httpsessionlistener, interface receiving notification events httpsession lifecycle changes.

override sessioncreated(httpsessionevent) method. sample code :

public class sessionlistener implements httpsessionlistener {    /**   * receives notification session has been created.   */   @override   public void sessioncreated(httpsessionevent se) {        httpsession session = se.getsession(); \\ handle httpsession object    system.out.println("sessioncreated");   }    /**   * receives notification session invalidated.   */   @override   public void sessiondestroyed(httpsessionevent se) {    }  } 

add listener class deployment descriptor web.xml :

 <listener>     <listener-class>sessionlistener</listener-class>  </listener> 

as @luiggi pointed out if using servlet 3.0 complaint container tomcat 7, can define listener class @weblistener annotation instead of declaring listener in web.xml, though prefer orthodox approach because can find listener information(except binding listeners) in 1 file itself.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -