How to prevent repeated online statistics in jsp

Source: Internet
Author: User
Tags log4j

There are three methods to prevent repeated online statistics: 1. Using database records 2. Using ServletContext applications
3. Use session.
The first approach is relatively simple, but it will cause a burden on the database. The second approach has not been implemented yet .:)
This article implements the practice of using Sessions. The basic idea is to create a session record login name during normal login, and then stimulate the listener.
The code is as follows:
1. Assume that loginINFO [0] is the login name and the session name is created.
If (rs_login.next ()){
Login_servlet.logger.info ("login verification successful"); // log4j
OnLineUser OLU = new OnLineUser ();//
If (! OLU. existUser (loginINFO [0]) {
Login_servlet.logger.info ("repeated login ");
Return;

} Else {
Session. setMaxInactiveInterval (3000); // The lifecycle of the session
Session. setAttribute (loginINFO [0], OLU );


                }
2. Listener code: OnLineUser
/*
* Creation date: 2005-5-12
 *
* Purpose:
 *
*/
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:
* Used to count the number of online users, prevent uniform Account logon and exit account cancellation
Related Article

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.