• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Compiler error

 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic