在sun问了一下得到回答如下:
Since you cannot access other sessions besides the current one, you will need to store the current users somewhere other than the session. Here is an option.
public class User implements HttpSessionBindingListener{
private String userid ;
private MyServlet servlet ;
public User(Stirng userid, MyServlet servlet) { this.userid = userid;
this.servlet = servlet ;
} //assume standard accessor Methods.
public void valueBound(HttpSessionBindingEvent ev) { getServlet().currentUsers.addElement( getUserID() );
}
public void valueUnBound(HttpSessionBindingEvent ev) {
for(int i = 0; i < getServlet().currentUsers.size(); i++) {
if( ((User)getServlet().currentUsers.elementAti)).getUserID().equals( getUserID() ) )
{
getServlet().currentUsers.remove(i);
break ;
}
}
}}
public class MyServlet extends HttpServlet{
public Vector currentUsers ;
}
Then, you can access the servlets currentUsers vector for a list of current users. Readup on HttpSessions and the HttpSessionBindingListener classes.
You will put the person's information in a Bean and then store it in the session when they logon/return/etc. The Listener handles the rest.