Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

SIMPLE java/jsp problem.

Thread view: 
questionmarc420@msn.com - 23 Jan 2006 16:42 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.