JSP Variable Scope
843833Oct 1 2001 — edited Dec 7 2005Hello,
I'm fairly new to JSP, so I apologize if this is a newbie question. I'm having a problem where it appears as though some variables I defined in the declaration area of my JSP page are shared by multiple clients. Here is a code snippet...
<%@ page import="java.util.*" %>
<jsp:useBean id="postSearch" scope="request" class="healthweb.PostBean" />
<%!
String hridErr = "";
String emplHrid = "";
String supvHrid = "";
String yourHrid = "";
boolean youAreEmpl = true;
boolean youAreSupv = false;
Hashtable[] empl;
Hashtable[] you;
Hashtable[] supv;
%>
<SCRIPT LANGUAGE="JavaScript">
alert("<%= request.getParameter("yHrid") %>");
alert("<%= youAreEmpl %>");
</SCRIPT>
...
As you can see, I'm initializing the youAreEmpl variable to true. However, if a client executes this JSP and the variable gets set to false, it seems to be false when other clients access the JSP initially.
I'm very confused by this. Doesn't each client receive its own scope and its own instance of the object created by the JSP page?