File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Head First - Final Mock Exam, Q55 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Head First - Final Mock Exam, Q55" Watch "Head First - Final Mock Exam, Q55" New topic
Author

Head First - Final Mock Exam, Q55

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

I've got two problems related with the given question (and basically about the JSP Documents):

1. Does JSP Document need to have a root element? I know that it might have a <jsp:root> element, but it doesn't have to. But the question is - is ANY root element in a JSP Document obligatory?

2. Do the template texts should be wrapped into <jsp:text>? Can't they be just loosely put without <jsp:text>?

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

Hi Pedro!

1. Does JSP Document need to have a root element? I know that it might have a <jsp:root> element, but it doesn't have to. But the question is - is ANY root element in a JSP Document obligatory?

No, see this part of the JSP2.0 spec:
JSP.6.2.2 Overview of Syntax of JSP Documents
A JSP document may or not have a <jsp:root> as its top element; <jsp:root> was mandatory in JSP 1.2, but we expect most JSP documents in JSP 2.0 not to use it.

2. Do the template texts should be wrapped into <jsp:text>? Can't they be just loosely put without <jsp:text>?

No, template text appearing in html tags like <b>hello</b> do not have to be wrapped up in a <jsp:text>.
However loose pieces of template text have to be wrapped up.

Regards,
Frits
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Frits for (as usual) rapid answer :-)

AD 1. I've read this part of the spec you quoted but as far as I understand it - it says only about the <jsp:root> and not about any other root element. I do know that the <jsp:root> is not required, but is ANY root element needed?
Or maybe I should rephrase the question: is the XML document valid if it doesn't contain any root element?

AD 2. What do you mean by saying "loose pieces of template text" which are not within tags? Could you please post an example of such JSP Document?

Thank you in advance!

Cheers!
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

Or maybe I should rephrase the question: is the XML document valid if it doesn't contain any root element?

Yes, although it is not clearly stated in the JSP2.0 specs, but more related to XML documents in general. A well-formed XML-document needs a root element (and from jsp2.0 onwards not necessarily a <jsp:root>)

What do you mean by saying "loose pieces of template text" which are not within tags? Could you please post an example of such JSP Document?

Some tag's (like for example <jsp:root>) do not allow anything other then tags inside them, like:

These pieces of "loose text" have to be wrapped up:

Regards,
Frits
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

I will check your second answer when I'll return home, but regarding the first one...

Frits wrote:
Pedro wrote:Or maybe I should rephrase the question: is the XML document valid if it doesn't contain any root element?

Yes, although it is not clearly stated in the JSP2.0 specs, but more related to XML documents in general. A well-formed XML-document needs a root element (and from jsp2.0 onwards not necessarily a <jsp:root>)


Until now I was sure that well-formed XML document must have a single root element... :

http://www.w3.org/TR/REC-xml/ wrote:Each XML document has both a logical and a physical structure. Physically, the document is composed of units called entities. An entity may refer to other entities to cause their inclusion in the document. A document begins in a "root" or document entity.(...)

Also:
http://www.tizag.com/xmlTutorial/xmldocument.php wrote:In any markup language, the first element to appear is called the "root element", which defines what kind of document the file will be. (...)
In an XML file, there can only be one root element. The root element must encapsulate all other elements--meaning, these other elements must show up after the opening root tag and before the closing root tag.


A valid XML Document is a document which is well-formed and it is correctly validated using XSD (or DTD), right? So the valid XML document is something more than just well-formed XML.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

Or maybe I should rephrase the question: is the XML document valid if it doesn't contain any root element?

Oh, I missed the doesn't! The JSP document needs a root element....
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Ok, glad we cleared this one up :-)

So the following code is an invalid JSP Document:

as there is no root element.

And another question - in JSP pages I don't need to specify the taglib for standard JSP library (tags starting with <jsp:...>), but I do need to do this in JSP Documents, right? So the following is incorrect:


as the <myRoot> should be replaced with <myRoot xmlns:jsp="http://java.sun.com/JSP/Page"> and then it would be a valid XML Document, right?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

as the <myRoot> should be replaced with <myRoot xmlns:jsp="http://java.sun.com/JSP/Page"> and then it would be a valid XML Document, right?

Correct.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

HF, Final Mock Exam, Q55 wrote:Given the following JSP:

An attempt is made to convert the above JSP to a JSP Document:

What is wrong with the new JSP Document? (Choose all that apply.)
A. No <jsp:root> was declared.
B. The template text should be wrapped in a <jsp:text> tag.
C. EL expressions are not allowed in JSP Documents.
D. The <jsp:expression> contents should not have a semicolon.


The answers B and D are correct (also there is wrongly copied variable name: TITLE vs GREETING).

So, considering our above conversation, the above JSP Document is not valid also because:
- not because it doesn't have a <jsp:root> (which is not mandatory) but because it doesn't have ANY root element,
- the lack of root element means that there is no "jsp" XML namespace defined, so none of the <jsp:...> tags is valid.

Am I right?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

I agree with you!

Regards
Frits
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Ok, thanks Frits for your help! :-)

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First - Final Mock Exam, Q55