The moose likes JSP and the fly likes What are the scriplet rules for conditionals without braces? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "What are the scriplet rules for conditionals without braces?" Watch "What are the scriplet rules for conditionals without braces?" New topic
Author

What are the scriplet rules for conditionals without braces?

Jay Urbain
Greenhorn

Joined: May 24, 2002
Posts: 4
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>


Jay Urbain<br />Upstream Development, LLC
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Jay Urbain
Greenhorn

Joined: May 24, 2002
Posts: 4
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
 
IntelliJ Java IDE
 
subject: What are the scriplet rules for conditionals without braces?
 
Threads others viewed
window.Print() not working.
How to run my own jsp file?
Problem with JSP using WSAD
problem while forwording the JSP page
Calling a servlet from a html page
IntelliJ Java IDE