HttpSessionBindingListener interface has a need to implement both methods: public synchronized void valueBound (HttpSessionBindingEvent httpsessionbindingevent) public synchronized void valueUnbound (HttpSessionBindingEvent httpsessionbindingevent)
When Session created, the servlet container will call the valueBound method; Session is called when it is deleted.
Specific applications can track each time the login user, record-related information, and timely delete information in time when it is timeout.
Example code is as follows: import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; ........ public synchronized void valueBound (HttpSessionBindingEvent httpsessionbindingevent) {// check is valid if ( ! Valid ()) return; // Check if the information already exists. There is no existence.
IF (Info.online.Containskey) {// Record log information log.info ("Initial User Context ...."); UserOnlineStruct UOS = (UserOnlineStruct) Info.omline.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 if Effective if (! Valid ()) return; // Delete user-related information // Record log information log.info ("Destory User Context ...."); info.online.remove;}
-------------------------------- 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