tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (David M. Karr)
Subject Re: newbie: why isn't jsp variable initialized?
Date Sat, 10 Feb 2001 01:02:09 GMT
>>>>> "Robert" == Robert Karen <> writes:
  Robert> Thanks. It worked. Could you give me a brief
  Robert> explanation? I guess the '<%' is dynamic while
  Robert> the <%! declaration is not. Is it part of the specs
  Robert> that Jsp variables are stored session to session?

The easy way to look at this (because that's exactly how it works), is
that "<%!" places the piece of code outside of the service method,
inside the class, but "<%" gets placed inside the service method

The result is that ordinary variables declared with "<%!" become
INSTANCE variables (not static as one person indicated), and variables
declared with "<%" become local variables of the service method.

So, when the servlet engine creates an instance of your servlet, the
instance variable will live ACROSS invocations of the servlet, but the
local variable will be reinitialized on every invocation.

If you have an instance variable that gets incremented every time you
invoke the servlet, then it will increase by one for every
invocation.  A local variable will not increment each time.

David M. Karr     ; w:(425)487-8312     ; TCSI & Best Consulting    ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)

View raw message