Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What are the scriplet rules for conditionals without braces?  RSS feed

 
Jay Urbain
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What are the JSP scriplet rules for handling conditionals that are not using { braces } to
denote code blocks?
I found an example similar to the one I created below in the SCWCD Certification book.
As it turns out, the example below generates:
"Howdy, Bill: welcome to overpricedstocks.com!
Your stocks are down today."
With Tomcat, the following servlet code is generated (note the ";")
from the example:
if( displayName ) out.write("\r\n ");
Is this standard behavior for all app servers?
Thanks,
Jay
Example:
<html>
<head><title>Untitled</title></head>
<body>
<% String name = "Bill";
boolean displayName = false;
if( displayName ) %>
<b>Howdy, <%= name %></b>:
<i>welcome to overpricedstocks.com!</i>
<br>
Your stocks are down today.
</body>
</html>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the JSP scriplet rules for handling conditionals that are not using { braces } to
denote code blocks?

Simple: don't!
You have no idea how many statements are going to be generated, so leaving off braces is just asking for trouble.
What compels you to leave off the braces?
hth,
bear
 
Jay Urbain
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,
It was discussed in the SCWCD Certification book and I thought I should know it for the test (you probably know how anal those certification exams could be).
I would think this behavior would be defined.
Tx,
Jay
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!