Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested code in If statement

 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this normal that the fragment of code

<% if (true)
textA
<%else%>
text B

is converted in this:

if (true)
out.write("\r\n");
out.write("textA\r\n");
else
out.write("\r\n");
out.write("text B\r\n");

is it conform to the spec ?

I think this should not be converted like that but like this:

if (true)
out.write("textA");
else
out.write("text B");

in the SCWCD study kit book, they say the following part of code:

<% if(userLoggedIn) %>
Welcome, <%=username%>

is converted to

if (userLoggedIn)
out.write("Welcome, ")
out.write(username)

So what should be the conversion ?

Do we have to always use curly braces around the code or not ?

Thanks in advance,
Tiggy
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Your code will not compile
because of a misssing "%>".

Your code is packed into a
try-catch-block.
Therefore its mutch better to use curly braces always.

Greetings
Karl
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's recommended to use the curly brackets to cope the snippets... Sometimes, we might accidently forget to code carefully... I always use curly brackets not only in JSP development, but also in simple Java applications...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic