aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP Question 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 "JSP Question" Watch "JSP Question" New topic
Author

JSP Question

Kim Ming Yap
Ranch Hand

Joined: Dec 17, 2008
Posts: 53

I'm studying SWCD by Charles Lyons (2nd edition) and i'm reviewing some questions about JSP. On page 262, here's the following question:

Which of the following cause the value 'yes' to be written to the response if the state scripting variable is true and 'no' otherwise?

A. <%=
if (state) {
"yes";
} else {
"false";
}
%>

B. <%=state? "yes" : "no"%>
C. <% if (state) %>yes<%else%>no
D. <% if (state) out.write("yes");
else out.write("no");%>
E. <% state? out.write("yes") : out.write("no");%>

Answer is B & D. I do understand the explanation to the answer given. However nothing is mention about why A is incorrect? I don't see why A is incorrect.
Any help is appreciated.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

This would better sit on the SCWCD forum as it's about a mock exam question.

In JSPs code inside scriptlet expressions (i.e. <%=%>) become the argument to the print method of the JspWriter hence using the option A wouldn't even compile the JSP. You can't use statements inside the print method.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Kim Ming Yap
Ranch Hand

Joined: Dec 17, 2008
Posts: 53

Thanks for your reply. I think A will return either "yes" or "no". I don't see any difference between A and B since both are statements returning strings.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

I think A will return either "yes" or "no". I don't see any difference between A and B since both are statements returning strings.

Code inside the if statement in option A is not a valid Java code. In option B it's an expression which returns either values defined. So the two options are completely different.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Kim,
Review the difference between:


and

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Question