Ashwani Kalra wrote:

> Hi all ,
> Can any body provide some information for the following  situation ?
>
> Since JSP page is compiled into  the servlet class that has only one
> instance(normally) and initilized only once. All the variables declared
> using <%! %> tags become the part of the member variables of the servlet
> class(i.e. page implementation class).
>

You are correct that declaring variables inside <%!  %> tags creates a variable
that is shared across multiple requests, since it becomes an instance variable in
your generated class.  If you want a variable specific to a request, use a regular
scriptlet instead ("<% %>"), because this creates a local variable inside the
generated service() method.  All local variables are maintained once per
simultaneous request, so the requests will not interfere with each other.

One potential downside is that local variables lose their existence (and therefore
their values) between requests.  If you need something saved from one request to
the next, you will need to store it someplace in the mean time.  The usual
mechanism is to use session scope java beans, which relies on the servlet
container to use mechanisms that identify which requests are coming from which
user.  More information on session management is available in the various
tutorials on servlets and JSP, and has been exhaustively discussed on this mailing
list.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to