You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Randy Layman <ra...@aswethink.com> on 2001/02/09 18:48:20 UTC

RE: Servlet Questions - Please Help!

	Both of your questions seem to come from missing two very important
points about web development:
	1.  Connections are stateless
	2.  Objects called sessions.  Basically each client is given some
identifying piece of information that they must send as part of each
connection to identify themselves.  This session then works basically as
your state storage.  Servlets handle the creation and managment of sessions,
you simply need to put information into the session.  This session is
available to all resources that the use accesses during the course of their
visit, not just single servlets.

Direct answers to your questions:
	1.  Yes, servlets are really designed to be stateless from a user
perspective, with the state being stored in the session.  There might be
some server-relevant state like the number of access since object creation
or a database connection, in-memory cache, etc.
	For the Tomcat servlet engine a new instance of the servlet is
created for each distinct URL that the servlet is accessed by (ignoring GET
and PATHINFO parameters).  So for most servlets you have one instance, but
in some cases you might get two or three.

	2.  See general answer.  In the uncomplicated view of things, Tomcat
sets a cookie for each user that contains their sessionID.  Then when Tomcat
gets the request it finds the session and makes it available to the servlet.
Don't worry, Tomcat can deal with clients that don't accept cookies, but
this gets messier to explain.  It still has some flaws (people can change
their cookies) that will only be resolved by a persistant or stateful web
connection, however that would drastically change the web's architecture.

	Randy

-----Original Message-----
From: Rezaul H. Safiuddin [mailto:kashif@cs.utexas.edu]
Sent: Friday, February 09, 2001 1:01 PM
To: tomcat-user@jakarta.apache.org
Subject: Servlet Questions - Please Help!



Hi I am doing some research work on servlets...I am trying to get some
feedback regarding the following questions. 

Expert's help needed : 

(1) when are servlet classes instantiated?  It seems
    that a web server will constantly reuse the same
    servlet object -- but I don't know how to create
    other instances.  All of this makes sense if servlets
    are stateless.  so (a) are servlets supposed to be
    stateless and (b) how are multiple instances of servlets
    created?

(2) it is common for people to enter data on one web page
    and have this information available on other (subsequent)
    web pages.  (e.g., the web ordering forms from Amazon.com).
    If servlets are stateless, how is the relationship between
    web pages (and the information they maintain) shared?
    (My guess is that subsequent pages have hidden text fields
    that maintain the shared information, but this seems like
    a hack...).

Any help will be appreciated. Thanks.

Kash


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, email: tomcat-user-help@jakarta.apache.org