Discussions

Web tier: servlets, JSP, Web frameworks: A variable in JSP

  1. A variable in JSP (1 messages)

    I create a java variable "int load = -1;" in a JSP page. At some points inside the page, depunds upon the condition, this variable will be set to 1. But, after it is set to 1, if I close my web browser and open a new web browser, this variable is still 1 but not -1 (I think it should be -1 when a new browser starts), what's the problem and how to get rid of it?

    Thank you.

    Threaded Messages (1)

  2. A variable in JSP[ Go to top ]

    Maybe you used the <%! syntax, which makes it a class variable (outside the service method of the generated servlet).

    If you did that, one instance of the variable exists and is shared by all requests. Use the scriptlet notation instead, which puts the variable INSIDE the service method (so there is one per request):

    <% int whatever=1; %>