Craig,

> I did not understand what you ment by "shared across all the threads..."
>
> Did you mean they are variables with scope as "application" (if we
> consider the JSP Scope semantics)
>
> If that is what you mean, then it is not so as per the specs'.
> If you have encountered it... well I don't know if this is an inconsistent
> behavior...
>
> I have tried out what you have referred here and for all purposes the
> variable I declared gave out different values, or instances.
>
> I have tried out with a simple Variable, but I have never tried a Function
> before, do you mean a function is not thread safe.
>
> I did a retest after I read your response, and I did get two different
> instances, for the variable (for two different instances of the same
> page).
>
> "Better choices would be to encapsulate Java logic in beans, custom tags,
> or Servlets."
> I agree completely with what you say about the above...
>
Amit Ghaste

> ----------
> From:         Craig R. McClanahan[SMTP:[EMAIL PROTECTED]]
> Sent:         Tuesday, January 04, 2000 10:58:30 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Simple question
> Auto forwarded by a Rule
>
> Attili Srinivas wrote:
>
> > Hi,
> > Does everything inside the <%   %> tags goes into the _jspService(
> )method ???
> > if not, how can we diffrentiate code(when writing JSP code)  that goes
> into the
> > _jspService( )method  and outside the method(say I want to write another
> > function abc())
> > Thanks
> >  Sri
> >
>
> The JSP syntax for putting variables and methods outside the service
> method is:
>
> <%!
>     private int myIntValue = 3;
>     private String myMethod(String arg) {
>         return arg.toUpperCase();
>     }
> %>
>
> However, a couple of cautionary notes are important:
>
> * Your JSP page is still being invoked in a multithreaded server, so
>   you have to write thread-safe code.  In particular, any variables you
>   declare this way are shared across all threads (they become
>   instance variables in the generated class).
>
> * If the function you are writing is anything other than simple formatting
>   stuff to help you generate the HTML, I would strongly encourage you
>   to reconsider.  Mixing business logic and presentation logic in your
>   pages will make your apps harder to maintain and enhance in the
>   future.  Better choices would be to encapsulate Java logic in beans,
>   custom tags, or servlets.
>
> 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