Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP Compiler error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP Compiler error" Watch "JSP Compiler error" New topic

JSP Compiler error

Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

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?

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Paul Yen

Joined: Feb 08, 2004
Posts: 19
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.

SCJP 1.4, SCWCD, SCBCD,<br />SCDJWS (preparing)
Venkatesh Subramanian

Joined: Sep 08, 2003
Posts: 7
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
jspWriter.print("\n"); //<BR>
jspWriter.print("str ="); //str =
jspWriter.print(str); //<%= str %>
SCJP 1.4
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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.
I agree. Here's the link:
subject: JSP Compiler error
It's not a secret anymore!