Yes, correct. That is why you shouldn't use that form of declaration for
anything except thread safe variables. In the example I gave it is a static
final which is guaranteed thread safe since it is a constant. If you do use
class variables in your JSP/Servlet then you will probably have to use a
single thread model of JSP which isn't supported well in Websphere 2.0x and
JSP 0.91 or you will have to synchronize any method that uses it and
anyplace in the JSP that uses the variables.
It isn't any better with the <%! form in JSP 1.x. As a developer you have to
be careful to make sure your JSP is thread safe. The easy way to do that is
to use the <%@ page isThreadSafe="false" %> switch. The problem with that is
it is very inefficient compared to the normal isThreadSafe="true"
implementation. Basically your whole JSP is either one user at a time or
each JSP invocation gets a new instance of the servlet, depending on the
implementation of the servlet/JSP engine.
-----Original Message-----
From: Marc Krisjanous [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 19, 2000 7:44 PM
To: [EMAIL PROTECTED]
Subject: Re: runat="server"?
but wouldn't that cause data corruption since the variable is an Instance
class variable and all threads could access it, possibly at the same time.
You would have to synchronized all methods that used the vars.
Marc
-----Original Message-----
From: Jim Bailey [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 20 June 2000 3:41 AM
To: [EMAIL PROTECTED]
Subject: Re: runat="server"?
As far as I can tell, the first example shouldn't be valid. It should create
a syntax error: "illegal modifier on local variable" or something like that.
The second example is valid on JSP 0.91 and Websphere 2.0x for sure but I
don't know how "standard" it is. It puts the variable myInt as a class
static variable on the servlet generated from the .JSP file. It is
equivalent to the following:
public class _int_test__jsp extends HttpServlet
{
private static final int myInt = 0;
public void
_jspService(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{... etc
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets