Hi,
An interesting  observation about the variables declared in JSP pages.

Any variable declared inside <% .... %> is local to the page and is not
visible to outside functions, even those declare on the same JSP.

Example:

<%
        int evilVariable = "666";
%>
...
function testFunction() {
        // do not see evilVariable from here
}

Why? evilVariable eventually becomes a local variable in the service()
method of the resulting servlet and so is not accessible by other methods of
that servlet.

Any variable declared inside <SCRIPT RUNAT=server></SCRIPT> become global
for any function declared in the servlet.

Example:
<SCRIPT RUNAT=server>

int evilVariable = "666";

</SCRIPT>
...
function testFunction() {
        int x = evilVariable; //can get to it
}

Why? evilVariable declared this way becomes a private member variable of the
resulting servlet and so is accessible by all other methods of that servlet.

Conclusion

It is important to understand this difference because in servlet environment
there will only be a single(!!!) instance of the resulting servlet running
and serving all requests for a particular page. Thus, potentially all of the
member variables of that servlet will be share across the requests as
opposed to variables local to the service() method that will be recreated
for each request. So, we should be careful about putting none constant
variables in <SERVER></SERVER>. At the same time, it might be useful to do
so in some situations.

Good Luck!:-)

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to