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