Prevent repeat online, statistics online number usually consists of three ways: 1. Records from the database 2. Use the ServletContext type of application 3.
The first approach is simpler but creates a burden on the database. The second approach has not yet been implemented.:)
This article implemented the practice of session, the basic idea is to establish a session log log name when normal landing, at this time to stimulate the listener. The
code is as follows:
1. Landing on the assumption of landing name Logininfo[0], set up the session record login name.
if (Rs_login.next ()) {
login_ Servlet.logger.info ("Login validation Successful");//log4j
Onlineuser olu=new onlineuser ();//
if (! Olu.existuser (Logininfo[0])) {
Login_servlet.logger.info ("repeat Landing");
return;
}else{
Session.setmaxinactiveinterval (3000); The life cycle of the session
Session.setattribute (Logininfo[0],olu);
}
2. Listener code: Onlineuser
/*
* Date Created 2005-5-12
*
Objective
*
*/
Package cn.wst.common.onLine;
Import javax.servlet.http.HttpSessionBindingEvent;
Import Javax.servlet.http.HttpSessionBindingListener;
Import Org.apache.log4j.Logger;
import java.util.*;
/**
* @author wangshangting
*
* Purpose:
* is used to count online numbers, prevent unified account login, exit cancellation account