Ways to prevent repetitive online statistics on online numbers

Source: Internet
Author: User
Tags log log log4j

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  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.