SIMPLE java/jsp problem.

Q

questionmarc420

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
 
I

isamura

: 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
 
J

James Westby

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


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
 
R

Roedy Green

------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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top