Thank you very much.
Now all my doubts are cleared about sessions.
I would certainly go to the site u mentioned.
Thanks
Srikanth patibanda
-----Original Message-----
From: Craig McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 14, 1999 4:20 PM
To: [EMAIL PROTECTED]
Subject: Re: Same session
"PATIBANDA, SRIKANTH" wrote:
> oh Thank you very very much.
> You cleared many of my questions & doubts.
> Now my concepts are getting cleared.
>
> What i understood from your explanation is
>
> HttpSession session = reqp.getSession(true);
> count = (Integer)session.getValue("track.count");
>
> By the above command i create a session and a variable track.count
> its a kind of counter.
This code actually retrieves a session variable that already exists (assumig
that your variable "count" is already defined to be of type Integer. You
have
to use the putValue() method to create a variable.
If you really wanted to track how many different requests a particular user
made within a particular session, you might do something like this
HttpSession session = req.getSession(true);
if (session.isNew()) {
Integer newCount = new Integer(0);
session.putValue("track.count", newCount);
} else {
Integer oldCount = (Integer) session.getValue("track.count");
Integer newCount = new Integer(oldCount.intValue() + 1);
session.putValue("track.count", newCount); // Replaces old one
}
in each of your servlets. Note that this is not a global hit counter --
because we have tied it only to this particular session.
>
> What happens to the session and variable once the user logs out.
> Does it going to die or if again some one logs it is going to use the
> previously stored
> value for the variable.
> OR
> One has to manually invalidate the session and variable before he logs
out.
> I want to understand the scope and availability of the session.
>
When the session dies, all variables that were stored in it disappear
(assuming
there was no other reference to them), and they become available for garbage
collection.
There are two possible ways for a session to die -- either you call
session.invalidate() yourself (which you would do in the "logout" processing
of
your application), or the session times out. The timeout interval is
measured
between requests that are made on the same session (whether or not they are
actually to the same servlet or JSP page). You can modify this timeout by
using session.setMaxInactiveInterval().
Note that if your user simply exits their browser, or surfs away to another
site, your application receives no notification of this. That's why the
timeout interval is there, so you won't have things hanging around forever.
>
> I really appreciate taking so much pain to explain me these
There is quite a lot to how sessions work beyond what can easily be
discussed
in an EMAIL forum like this. I would suggest checking out the Servlet Trail
in
the Java Language Tutorial (http://java.sun.com/docs/books/tutorial), and/or
get one of the several books about servlets.
>
> Thank you
> srikanth
>
Craig McClanahan
___________________________________________________________________________
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
___________________________________________________________________________
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