Re: Newbie functions question

From: Ryan Stewart (zaphod_at_no.texas.spam.net)
Date: 01/14/04


Date: Wed, 14 Jan 2004 12:25:16 -0600


"Stuart Palmer" <tryandspamme@youcant.com> wrote in message
news:bu3gc3$2tk4$1@sp15en20.hursley.ibm.com...
*fixed top post*
> "Ryan Stewart" <zaphod@no.texas.spam.net> wrote in message
> news:PYKdnT1XuN51p5jdU-KYkQ@texas.net...
> > Actually, you can just put the method in the JSP:
> > <%!
> > private String testMethod(String str) {
> > String newString = str + " :: modified by method";
> > return newString;
> > }
> >
> > %>
> >
> >
> Thx Ryan,
> How would i call this function?
>
> <%=testMethod("Test");%>
>
> This comes up with an error for me.
>
> Many thanks as this looks like what I am after.
>
> Stu

Get rid of the semicolon or the equals. The <%= means an expression follows:
an expression being something that evaluates to a value. The <% means that
executable code follows. So in a page, you can do:
<%
    String blah = "Hello world.";
%>

    <p>Some HTML stuff</p>
    <p>Here is your string: <%= blah %></p>

Or you can do:
<%
    String blah = "Hello world.";
%>

    <p>Some HTML stuff</p>
    <p>Here is your string: <% out.println(blah); %></p>

The two will produce identical output. In your case, it would be
<%= testMethod("Test") %>
or
<% out.println(testMethod("Test")); %>