hi,
for some reason i can't add a method within jsp tags?
it says : Illegal start of expression.
Here's the code:
<%
....
------THE ERROR IS HERE THE METHOD DECLARATION IS THE ILLEGAL START OF
EXPRESSION
public void preserveTag(int i){
if(i==0){
data_body.replaceFirst("\\*T","<pre>");
}else
data_body.replaceFirst("\\*T","</pre>");
}
StringTokenizer x = new StringTokenizer(data_body);
int order = 0;
while(x.hasMoreTokens()){
// out.println(x.nextToken());
if(x.nextToken().equals("*T")){
out.println("FOUND *T");
if(order==0){
out.println("OPEN TAG");
preserveTag(order);
//data_body.replaceFirst("\\*T","<pre>");
order = 1;
}else {
out.println("CLOSE TAG");
//data_body.replaceFirst("\\*T","</pre>");
preserveTag(order);
order = 0;
}
}
}
....
%>
Now im sure hte asnwer is really simple but for some reason i can't
find out anywhere? If someone knows my problem please help
thanks
-morc
isamura - 23 Jan 2006 17:58 GMT
: hi,
: for some reason i can't add a method within jsp tags?
: it says : Illegal start of expression.
:
: Here's the code:
: <%
Try wrap method declarations in <%! ... %> instead.
.k
James Westby - 23 Jan 2006 18:06 GMT
> hi,
> for some reason i can't add a method within jsp tags?
[quoted text clipped - 39 lines]
> thanks
> -morc
Just a guess, but try the method
public void preserveTag(int i){
...
}
inside
<%! ... %>
as things inside
<% ... %> go inside the service() method of the generated servlet, and
so cannot contain method declarations.
You will need to add parameters/return values as appropriate fo
accessing what I guess was local variables before.
James
Roedy Green - 23 Jan 2006 20:49 GMT
>------THE ERROR IS HERE THE METHOD DECLARATION IS THE ILLEGAL START OF
>EXPRESSION
Usually those sorts of message the trouble is not exactly where it is
pointing. That's where in it from the parser's point of view. What you
need to correct it is often up or downstream.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.