• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Misleading Question like this

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.<jsp:root xmlns:"http://java.sun.com/JSP/page" version="2.0">
2. <jsp irective.page 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>
11.</jsp:root>
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++)
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks.
 
Charles Lyons
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic