In a recent project, jsp (the preferred choice for SUN Enterprise Applications) is used to achieve user logon, and session persistence is of course used. This is implemented using the implements HttpSessionBindingListener interface. This 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 ");
}
}
Call
OnLineUser onLineUser = new OnLineUser ();
Request. getSession (false). setAttribute (login_no, onLineUser );
Login_no indicates that the variable is the logon name. At the same time, set request. getSession (false) to false, which has two values: true and false. true is created if there is no same session. If yes, It is overwritten. If no, it is created. If yes, It is not created. I use this method to implement Single-point logon. Therefore, false is used. In this way, you can listen to the session you created. If the session times out, the valueUnbound method is executed. Create a session and run the valuebound method. Here, I want to change a person's status field. In this way, when this user is online and another user is online on another machine, I can make a judgment on the login page. There are many materials on the Internet, and the problem is that when the session timeout time is set to 1 minute. If the user does not exit normally, the user can change the offline status after one minute. However, if the user does not perform any operations on the computer within one minute, the user will also be suspended. I have been searching online for a long time, no such information is available. Later, I used my framework (my program uses the framework, and I use the bottom framework)
Javax. servlet. http. HttpSession session2 = request. getSession (false );
Com. chinantn. oa. util. OASession oasession =
(Com. chinantn. oa. util. OASession) session2.getAttribute ("oasession ");
This is a session processing class used on my login page. Then add
<Meta http-equiv = "refresh" content = "30; URL = foot. jsp (preferred for SUN Enterprise Applications)">. auto refresh.
The interval is less than the session Timeout time. The main purpose is to solve the problem by automatically refreshing the Access session if the page is not accessed within the timeout period.
Because I have not found any article on the Internet to solve this problem for a long time, I want to write out the solution I want to solve it later. I hope it will help those who have encountered this kind of problem. If you have any questions, contact me, ljunjie@gmail.com.