The behaviour that you notice is not due to the session, but because of the
variable "count" which you have declared as a class variable and not a local
variable to the _jspService method.

It would be better if you understand the difference between the variables
that are declared withing the declarative tags i.e. <%! ........... %> and
those that are declared between the scriptlet tags i.e. <%..........%> as
well as have a look at the source code of the you jsp generated servlet
file.

If you have a look at the archives you can get great deal of explanation on
the above, courtesy the jsp gurus on this mailing list.
Have a nice day.
With regards,
Sachin S. Khanna.
www.emailanorder.com
----- Original Message -----
From: Barry Burd <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 11, 2000 5:24 AM
Subject: Behavior of the implicit session object?


> I thought I understood the JSP session object, but then I observed the
> following behavior. The code that I'm executing is
>
> <br>Attributes:<br>
> <%! int count=1; %>
> <%= session.getMaxInactiveInterval() %> <br>
> <b><%= session.getAttribute("numVisits") %></b>
> <% session.setAttribute("numVisits", Integer.toString(count++)); %>
>
> When I open my Web browser, and visit this page, I get
>
> Attributes:
> 1800
> null
>
> Then, when I click Refresh, I get
>
> Attributes:
> 1800
> 17
>
> The reason for the number 17 is because I had visited this page sixteen
> with the same Browser before closing and reopening the browser. So my
first
> question is, why do I start with null again whenever I close and reopen
the
> Web browser (even though the session keeps track of how many times I had
> visited the page before newly opening the browser)?
>
> The second question relates to the visiting of the page from a different
> computer. I go to another computer on the same LAN. (Call this other
> computer "computer B".) I visit the same jsp page using computer B. First
> I get the null value, then 2, then 3, then 4. OK - that's what I'd expect.
> But then, I go back to the original computer (the one on which I counted
> up to 17) and I open my Web browser on that computer once again. This
time,
> I start out with the value null, but then get the value 5 (the number that
> I stopped at when I walked away from computer B). Shouldn't both computers
> maintain their own places in the numbering, since a session is specific
> to a single computer? That is, when I go back to the original computer,
> shouldn't the numbers start from 18, where I left off before?
>
> Thanks.
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> 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
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
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

Reply via email to