HttpSessionBindingListener interface has two methods parties need to implement: time public synchronized void valueBound (HttpSessionBindingEvent httpsessionbindingevent) public synchronized void valueUnbound (HttpSessionBindingEvent httpsessionbindingevent) Session created Servlet container will call valueBound method; Session deleted valueUnbound method is called when a specific application can be. Track each time you log in to the user, record information, and timely delete information in time. Instance code is as follows: import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory ; ........ public synchronized void valuebound (httpsessionBindingEvent httpsessionBounding) {// Check if the valid if (! value) return; // Check if the information already exists. No existence added. IF (Info.Online .Containskey (m_userid)) {// Record log information log.info ("Initial user context ...."); useronlinestruct uos = (useronlinestruct) info.online.get (m_userid); uos.loginip = uos.loginip; uOS.loginTime = uos.loginTime; UOS.sessionId = uos.sessionId;} else {Info.online.put (m_userId, uos);!}} public synchronized void valueUnbound (HttpSessionBindingEvent httpsessionbindingevent) {// check is valid if (valid ()) Return; // Delete the user-related information // Record log information log.info ("Destory User Context ....") Info.online.remove (m_userid);} -------------------------------- If you don't use log4j, You can change log.info () to system.out.println () will get the same result. If you want to configure log4j, please click on the log record. If you have any questions, please contact me: WebMaster @ BCXY.com
Author Blog:
http://blog.9cbs.net/ezerg/
related articles
Design and Development Environment Configuration Document Integration Test STRTUS Spring Hibernate Hibernate Batch Delete Efficiency Analysis Java Dynamic Agent Class Implementation Memory Function JBoss 4 JDBC Connection JDBC