|
Re: User management / Session management question: msg#00076java.enhydra.general
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 27 Nov 2002, Boris Klug wrote: > ... > 1) How can I get a list of all active session? At best with the related > session data and the last requested presentation object? I want to use it for > a admin page so the admin can see who is logged in. > for this try: ############################################################################# Vector sessions=null; Enhydra.register(Thread.currentThread(), comms.application); try{ sessions = activeSessions(); }finally{ Enhydra.unRegister(Thread.currentThread()); } StandardSession s; Date d = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy HH:mm:ss"); buf.append("<TR><TD>Key</TD><TD>Created</TD><TD>Expires</TD><TD>LastUsed</TD><TD>Used Time</TD><TD>isNew?</TD></TR>\n"); for(int i=0; i < sessions.size(); i++){ s = (StandardSession) sessions.elementAt(i); buf.append("<TR><TD>"); buf.append(s.getSessionKey() ); buf.append("</TD>"); buf.append("<TD>") ; d.setTime(s.getTimeCreated()); buf.append(df.format( d ) ); buf.append("</TD>"); buf.append("<TD>") ; d.setTime(s.getTimeExpires()); buf.append(df.format( d ) ); buf.append("</TD>"); buf.append("<TD>") ; d.setTime(s.getTimeLastUsed()); buf.append(df.format( d ) ); buf.append("</TD>"); buf.append("<TD>") ; buf.append(((s.getTimeLastUsed()-s.getTimeCreated())/1000.)); buf.append(" s</TD>"); buf.append("<TD>") ; buf.append(s.isNew()); buf.append("</TD></TR>\n"); ... } ... private Vector activeSessions() { Vector sessions = new Vector(); try{ StandardSessionManager sm = (StandardSessionManager)Enhydra.getSessionManager(); Enumeration keys = sm.getSessionKeys(); Session session; while(keys.hasMoreElements()) { sessions.addElement(sm.getSaveSession(Thread.currentThread(),(String)keys.nextElement())); } } catch (Exception e) { //throw e; } return sessions; } #################################################################### Attention! i use a method getSaveSession(...) because getSession(...) set the LastUsed time stamp. So i patch this new Funktion in the StandardSessionManager class. (The Code is part of a quick hack info servlet :-) - -- sincerely Mike Schubert Tel.: ++49-351-3 18 09 15 interface projects GmbH Fax.: ++49-351-3 36 11 87 Tolkewitzer Str.49 E-Mail: mike.schubert@xxxxxxxx D-01277 D R E S D E N HTTP: www.interface-business.de/ "FreeBSD is like a wigwam, no windows, no gates and an apache inside." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (SunOS) Comment: For info see http://www.gnupg.org iD8DBQE95J7h5Vi8Cl3EtEoRAmiRAJ9c5rOkga6LeUjN31ba+QYmspvxlACglOjz gJfL47Q1F19PdJGzMq6mmOo= =v+8i -----END PGP SIGNATURE-----
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | User management / Session management question, Boris Klug |
|---|---|
| Next by Date: | Re: need help with sessions, Terry Steichen |
| Previous by Thread: | User management / Session management question, Boris Klug |
| Next by Thread: | enhydra & cofax, Ben Philyaw |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |