jQuery in Action, 2nd edition*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP Compiler error" Watch "JSP Compiler error" New topic
Author

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
Greenhorn

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
Greenhorn

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
else
jspWriter.print("\n"); //<BR>
jspWriter.print("str ="); //str =
jspWriter.print(str); //<%= str %>
Thanks,
Venkatesh.
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.
 
jQuery in Action, 2nd edition
 
subject: JSP Compiler error
 
Similar Threads
JavaMail - Reopening a pop3 folder
Bean instantiation from JSP
JavaBean problem Tomcat 5.5
Unable to create a bean for class myclass?
required jars