> In the init() method of my servlet I create a vector object.Whenever the
> Agent logs in I check in the vector whether that agent id is there or not.
> If it is not there then I put the Id into the vector ELSE I give a message
> Agent already logged in.
Why not store the login as key in a Hashtable with the SessionId as
value. If some user logs in, you check if the sessionId that
corresponds with his login still is a valid session.
If not the user can login, otherwise you inform him of the fact
that there is still an active session with his login...
> This works fine if he uses the logoff option of my system BUT when the user
> closes his browser the AgentID still remains in the vector and if he logs in
> again it says "Agent already logged in" though he is not.
>
> How do I handle this event(closing of browser)???
> I want to remove the Agent Id from the vector when the user closes his
> browser.
In most servers you can set a Timeout-value. For instance: if the
user doesn't do anything for 30 minutes his session is invalidated
automatically.
This has nothing to do with your problem, but it could be
a nice feature:
In the application we are developing, we have an abstract servlet
of which all our other servlets inherit. This abstract servlet
has two static variables: a boolean shutdown and a String message.
In a special HELPDESK-servlet. We can monitor all the current
valid sessions (with getSessionContext). You can see who is logged
in and from what IP-adress.
We also show the number of minutes since the creation of the
session and the last hit. You can see how every session times
out after half an hour.
If we plan to shutdown the server for maintenance, we set the
static boolean shutdown = true and write something in the static
String message. As soon as the boolean shutdown = true, the users
can only do one more hit (for instance to submit the data they
entered in a form), after that the abstract servlet invalidates
their session and they are redirected to a login servlet that
shows the message (for instance: the server wil be shutdown for
maintenance. Please try again later).
Servlets are great, don't you agree?
--
-------------------------------------------------------------------
Bruno Lowagie Academisch Rekencentrum Universiteit Gent
Tel : 09/264.48.14 e-mail : [EMAIL PROTECTED]
-------------------------------------------------------------------
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html