/ ** This is a class that manages user information.
File name onlineuser.java
* /
Import javax.servlet.http. *; import javax.servlet. *; import java.util. *;
Public class onlineuser imports httpsessionBindingListener {public onlineuseuser () {}
private Vector users = new Vector (); public int getCount () {users.trimToSize (); return users.capacity ();} public boolean existUser (String userName) {users.trimToSize (); boolean existUser = false; for ( INT i = 0; i Public Boolean Deleteuser (String UserName) {Users.trimtosize (); if (User (User ") {Int CurruserIndex = -1; for (INT i = 0; i Public Vector getonlineuser () {return.com (httpsessionBindingEvent E) {users.trimtosize (); if (! existuser (E.GETNAME ())) {users.add (E.GETNAME ()); system. Out.print (E.GetName () "/ t login to system / T" ("Number of online users:" getCount ());} else system .out.println (E.GetName () "already exists");} Public void valueunbound (httpsessionBindingEvent e) {username = E.GETNAME (); deleteuser (username); system.out.print (username / t exit system / t " (New Date ()) ); System.out.println ("Online User:" getCount ());}} / <% / ** This is a JSP file display online user File name onlineUser.jsp * /%> <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page import = "@ @ Page Import =" @ JSP: usebean id = "onlineuser" class = " Onlineuser "Scope =" Application "/> ELAPSED production p> p> <% out.println (" Landing successfully, welcome you to access! < / h1> p> center> <% session = request.getSession (false);%> <% string username = request.getParameter ("username"); IF (ONLineUser.existuser (UserName) {OUT. Println ("User username " font> has been logged in! ");} else {session.setMaxINActiveInterval (50); file: // seesion is effective, in seconds unit session.setttribute ( Username, onlineuser; out.println ("Welcome new users: " username " font> login to the system!");} out.println ("
Current online user number: < Font color = red> " onlineuser.getCount () " font>
"); Vector vt = onlineUser.getonlineuser (); enumeration E = vt.efficient (); out.println (" online user list "); Out.println (" "); OUT.Println ("
User Name TD> TR> "); while (E.hasMoreElements ()) { Out.println (" "); OUT .println (Strint) E.NEXTELEMENT () "
"); out.println (" td> tr>");} out.println (" table>");%>