Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why is this expression wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why is this expression wrong?" Watch "Why is this expression wrong?" New topic

Why is this expression wrong?

Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 88

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

Joined: Jul 19, 2004
Posts: 8384

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.

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
I agree. Here's the link:
subject: Why is this expression wrong?
It's not a secret anymore!