Dennis-
  The <%! tag sets up an instance variable which is only initialized when
the JSP's servlet is instantiated. There is only one instance of the servlet
class (usually just one) running in the JSP engine. You probably should have
just declared it like this:

<% String str=""; %>  (i..e remove the !)

When you declare it as a member variable, each thread running your JSP can
modify it.  You could potentially have a situation where two threads execute
the str=i+"<br>+str at the same time and end up with doubled lines.That is,
a thread might see
9
8
7
7
6
5
4
4

Hope that helps,
    Mark

----- Original Message -----
From: "Dennis Huang" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 14, 2000 11:30 PM
Subject: Something strange


> Hi:
>
> I have a piece of code look like this:
>
> <%! String str=""; %>
> <% for (int i=1; i < 10; i++) { str = i +"<br>"+str; } %>
> Before <B>JSP</B> Output <P>
> <%= str %>
> <P> After <B>JSP</B> Output
>
> This works. The strange thing is each time I click on the Refresh,  <%=str
> %> outputs more and more repeated values(from 9 to 1). It seems <%! String
> str=""; %> does not work from the second time I click on the Refresh
button.
> Do you know why? I am using Tomcat and IE5.
>

===========================================================================
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

Reply via email to