--- Raymond Xu <[EMAIL PROTECTED]> wrote:
> Hi, I just built up a few pages which can use
> session attributes to judge
> whether a user has logged in. I don't know how to
> count how many users have
> logged in at the same.
>
> Any help will be appreciated!!
>
> Raymond
>
One way of doing this is to create an
application-scope variable (an Integer in
getServletContext()) which contains the current number
of active sessions. You simply increment this when
somebody logs on and decrement this when he/she logs
off.
As an alternative to using an Integer object, you can
use a map (most likely a Hashtable) to store/delete
the session objects (HttpSession).
In any case, it might be helpful to create a 'cleanup'
program which would be invoked every time a session is
invalidated or had timed out. Check out about
HttpSession Binding Listener interface, esp. the
valueUnbound() method.
Hope this helps. Good luck.
Dingdong Lorico
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body:
> "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets