You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by Petr Suchomel <ps...@itsignet.cz> on 2000/02/23 13:11:32 UTC

Declaring a using function in JSP

I'd like to use function in JSP file like that

f.e. 

This is classic function
public void test(String s)
{
    out.println(s);
}

and in JSP I need use it like this

<!%
public void test(String s)
{
%>
<br>
<%=s%>
<br>
<!%
}
%>

but the variable s is not in scope.

Can you help me?

Thanks Petr

P.S. I don't want to rewrite all the code to java syntax, and don't want use global variables.



Re: Declaring a using function in JSP

Posted by Danno Ferrin <sh...@earthlink.net>.
Sorry, JSP won't let you do what you are trying to do.  Declarations do
not scope like scriptlets do.  Declarations are meant to be self
contained units that fit in the class proper, and hence the control
structures must be complete.  Scriptlets are defined to be complete when
considered as whole in the document, but not the declarations, so the
two declarations are invalid since they are only partial declarations.  

Perhaps after 3.1 goes golden a JavaCC grammar checker could be put in
so the reported error would be an incomplete declaration rather than
passing it off to the compiler and letting it descramble what is going
on (especially since the second declaration could legally be sequenced
before the first one in the generated java code)

--Danno

Petr Suchomel wrote:
> 
> I'd like to use function in JSP file like that
> 
> f.e.
> 
> This is classic function
> public void test(String s)
> {
>     out.println(s);
> }
> 
> and in JSP I need use it like this
> 
> <!%
> public void test(String s)
> {
> %>
> <br>
> <%=s%>
> <br>
> <!%
> }
> %>
> 
> but the variable s is not in scope.
> 
> Can you help me?
> 
> Thanks Petr
> 
> P.S. I don't want to rewrite all the code to java syntax, and don't want use global variables.