Ashwani Kalra wrote:

> Hi all
> One basic question. What is the scope the variable that are declared using
> <%! %> tags when that page is compiled into servelet. Is it private, public
> , protected.can some other servelet or jsp access those variables.
>

The scope is whatever you define when you declare the variable, exactly like it is
in Java:

<%!
    public int aPublicInteger;
    private String aPrivateString;
%>

The page compiler just copies whatever you put here into the class it is creating
(so these become instance variables) -- it does not modify (or even understand)
what you are writing.

Even if you declare an instance variable (or a method) to be public, you are going
to have a hard time accessing it from a different servlet or JSP page, because
there is no way (within the servlet API) to retrieve a reference to an instance of
your JSP page.  But even if there was, that is really poor programming practice
IMHO -- you should place things that need to be shared in the appropriate scope
(usually session scope for user-related things) instead of trying to access the
"internals" of other JSP pages or servlets.


>
> Thanks
> Ashwani
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to