JSP project to close the browser after the puppet, as long as do not close the operation also remain online

Source: Internet
Author: User
Tags integer
js| Browser | project | Online recently a project with JSP to implement user login, of course, using the session to maintain. This is done using the implements Httpsessionbindinglistener interface, which is the brief code I wrote.
public class Onlineuser implements Httpsessionbindinglistener {
Private NewUser Newuser=null;
Public Onlineuser () {
Newuser=new NewUser ();
}


public boolean existuser (String str)
{
return false;
}

public void Valuebound (Httpsessionbindingevent e) {
String Tempname=e.getname ();
Integer m=new integer (tempname);
Newuser.setusername (Tempname);
try {
Newuser.updateonline ();
}
catch (Exception ex) {
}
System.out.println ("User" +tempname+ "upper Limit");
}

public void Valueunbound (Httpsessionbindingevent e) {
String Tempname=e.getname ();
Integer m=new integer (tempname);
Newuser.setusername (Tempname);
try {
Newuser.updateunline ();
}
catch (Exception ex) {
}
System.out.println ("User" +tempname+ "lower limit");
}
}

Called in the servlet for logon processing
Onlineuser onlineuser=new Onlineuser ();
Request.getsession (False). setattribute (Login_no,onlineuser);
Where Login_no is the variable is the login name. To set the Request.getsession (false) value to False, he has a value of true and false two, true if it is created if there is no same session. If there is coverage, false is not created, then not created, I want to use this to achieve a single sign-on so use false. This will allow you to monitor the session you created. If the session times out, the Valueunbound method is executed. Creating a session executes the Valuebound method. I'm here to make a change to a person's status field. So when the user is online, another user on the other machine on the line on the landing page I can be judged. There are a lot of information on the web, and then the problem is when you set the session timeout time to 1 minutes. User's abnormal exit can change the user's offline status in one minute, but if the user does not operate the computer in 1 minutes, it will be puppet, I have been searching on the internet for a long time and have no information on this. Then I used one of my frames (my program was framed and I used the bottom frame)
Javax.servlet.http.HttpSession Session2 = Request.getsession (false);
Com.chinantn.oa.util.OASession oasession =
(com.chinantn.oa.util.OASession) Session2.getattribute ("Oasession");
This is my login page with a session-handling class. And then add it to this page.
<meta http-equiv= "Refresh" content= "30; Url=foot.jsp "" To make automatic refresh.
The interval time is less than the session timeout. The main purpose is to use this automatic refresh to access the session to solve the problem if the page does not have access during the timeout period.




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.