Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Nested code in If statement

 
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
 
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
 
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...
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic