tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Janicki <Jani...@ia-inc.com>
Subject Re: JSP: SingleThreadModel + page variables
Date Sun, 20 Feb 2000 03:16:43 GMT
I've personally found it a big help to look at the java files created in the work
directory for each jsp.  I was really confused on how everything worked until
I investigated some of those dynamically build java files.  By comparing your jsp
file to the java output, you can more predictably write and debug good jsp code.

Chris


"Craig R. McClanahan" wrote:

> Andy Nuss wrote:
>
> > Hi,
> >
> > I've read about the variables which persist on a page:
> >
> > <%! int myvar; %>
> >
> > and I'm worried that the only way that a typical Web Server can compile this
> > page successfully to a Servlet is by implementing the SingleThreadModel
> > interface!  I infer this because it claims somewhere on Sun's site that
> > these variables are class variables.  Obviously 2 threads using the
> > same instance of the servlet, each responding to their own GET requests
> > would be stomping on each others variables unless the SingleThreadModel
> > is used.
> >
>
> You are correct, although the way to refer to them is instance variables,
> rather than class variables.  Such variables are shared across requests to this
> JSP page -- both simultaneous and subsequent.
>
> Note that SingleThreadModel would solve the first problem, but not the second
> -- the variable would live on as long as this particular page has been loaded.
>
> >
> > Am I correct?  Is it a requirement that these variables be implemented as
> > class variables?  Can they be implemented as variables declared at the top
> > of the scope of the doGet() method?  By a smart Web Server?
> >
>
> If you want a local variable that doesn't get clobbered by concurrent requests,
> just remove the "!" sign and say
>
>     <% int myvar; %>
>
> This variable gets declared inside the doGet()/doPut() method, so it is
> allocated on the stack.
>
> >
> > Thanks,
> > Andy
> >
>
> Craig McClanahan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message