Java Reference
In-Depth Information
http://localhost:8080/examples/servlets/servlet/CounterServlet
8. When the servlet runs, the result should look like this in the browser:
Counter Page
Welcome to the Web site
You have been here 1 time(s)s
9. Click Refresh several times and the number 1 should increment by 1 every
time you refresh the page.
R EVIEWING THE E XERCISES
Let's review the simple servlet you've created. This servlet created a session the first
time it was invoked and stored an integer object into the session. Every time the
servlet was invoked again, the integer object was retrieved, the count was incre-
mented, and an updated integer object was placed back into the session.
You could have created an int class variable and incremented its value every
time you invoked the servlet without creating a session. The result with a single user
would have been indistinguishable from the result you achieved using an integer
object stored in the session. This approach would have failed to give the correct re-
sult if there were two users because it would show the combined count for both
users rather than the user-specific count that the CounterServlet tracked for you.
Search WWH ::




Custom Search