File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Misleading Question like this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Misleading Question like this" Watch "Misleading Question like this" New topic

Misleading Question like this

Karne Reddy
Ranch Hand

Joined: May 28, 2006
Posts: 35
1.<jsp:root xmlns:"" version="2.0">
2. <jsp contentType="text/html" />
3. <h1>Hello</h1>
4. <jsp:scriptlet>
5. for(int i=0; i<5; i++)
6. {
7. out.println("World");
8. }
9. </jsp:scriptlet>
10. <jsp:text>!!!</jsp:text>
Which of the following statements are correct?

Select 1 correct option.
a This will generate output without any errors.

b Line 3 must be enclosed in <jsp:text> and </jsp:text>.

c Although line 3 is valid but "Hello" will not be displayed as HEADER1 format in the browser.

d Line 5 is invalid.
e Line 10 is invalid.

I thought ans is A but
Anwer is D
Because of
It should be written as:
for(int i=0; i&lt;5; i++)

Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
This isn't a "misleading" question - it's a small but simple thing to test. For example, I mention this on p.275 of my book:
The body content in each of these elements should be valid Java code, as would appear in the JSP scripting elements, except to ensure the document is well-formed XML you should use a CDATA section or replace & and < characters with the entity references &amp; and &lt; respectively.
I also make reference to it with operators such as <= in EL (use "le" instead). Without giving too much away, there's also a couple of test questions along these lines.
[ July 22, 2006: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Ke Cheng

Joined: Oct 05, 2005
Posts: 5
So the <h1> tag here is legal without being enclosed by <jsp:text> ? I thought template text should all be enclosed by <jsp:text>. Someone help me out here?

Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
The <h1> is perfectly valid... this is probably because the JSP document isn't associated with any particular DTD or Schema (although it has a namespace), so the document content isn't restricted. However, it should be well formed, which is where <jsp:text> comes in - this is useful for fragments of documents which otherwise wouldn't be valid. For example:However, in practise the <jsp:text> isn't required as this will also work okay in a JSP document*:Note that nearly all cases where a CDATA would be used in a document are unnecessary if EL is used:which is a valid document (and the primary reason why EL is used).

* For a JSP page, the <jsp:text> is required for this example to work correctly; having the CDATA alone will just cause the CDATA to be output to be the client. However, this would all be unnecessary for a page, because a page doesn't need to be well-formed anyway.
[ July 23, 2006: Message edited by: Charles Lyons ]
wood burning stoves
subject: Misleading Question like this
jQuery in Action, 3rd edition