• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Compiler error

 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When I run this on Tomcat 5.0 I get the following compiler error:

If I add curlies around the if and else clauses it works:

Is there something in the spec that I've missed or is this a problem with Tomcat 5?
 
Paul Yen
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
In SCWCD Exam Study Kit, it mentions that if you omit the braces might cause an error at compile time or an undesired behavior at runtime.
 
Venkatesh Subramanian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Your JSP code may have only one line of code after the 'if'. But when it gets translated into a servlet, the single line of jsp code may represented by more lines. In your case, the translated code may look like:
if (str.equals(""))
jspWriter.print("\n"); //<BR>
jspWriter.print("str is empty"); //str is empty
else
jspWriter.print("\n"); //<BR>
jspWriter.print("str ="); //str =
jspWriter.print(str); //<%= str %>
Thanks,
Venkatesh.
SCJP 1.4
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Venkatesh,
That makes sense. You know I always bracket my ifs anyway in pure Java code, I was just being lazy this time and it bit me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic