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).
>
> Now consider follwing scenario.
> I have declared one int variable and initilized to 0. My first http request
> to this variable sets to some other value say 100.Now my question is that if
> i make another request to same page and display this variable . What will be
> ouptput 0 or 100.(looks that it should be 100 but this will create problem
> for me. because my second request is expecting 0 value to be used in
> calculation.)
> can any Body suggest a solution for this so that each page will have its own
> value.
> eagerly waiting for reply!!!!!!!!
My general advice is, don't use <%! %> at all. It creates exactly the multi-threading
problem you describe.
If the value is only needed during processing of one request, and depending on how
the value is used, use scriptlets to declare the variable as a local variable
or beans with page or request scope.
If the value must be available across requests, use session scope, or application
scope if it must also be available to other clients. But with session and
application scope you need to consider multi-threading issues again.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
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