• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is this expression wrong?

 
Joey Sanchez
Ranch Hand
Posts: 88
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We know that the scripting variable state is true.

Why is this expression wrong? How would it be the code into _jspService method after translation?


And this is correct


because returns a value and it would appear into _jspService as

 
Roel De Nijs
Sheriff
Posts: 10204
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP expressions <%= ... %> are placed inside a out.print()

So <%= state ? "yes" : "no" %> is converted into out.println(state ? "yes" : "no");, which compiles without any problem. But with the if-statement the resulting code won't compile. That's also why semicolon in a jsp expression is not allowed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic