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 );
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