Creating Static and Dynamic Content
Creating Static and Dynamic Content
Note that jsp:root is required because otherwise books.jspx would have two root elements:
<books>
and <magazines>. The output generated from books.jspx will be a sequence of XML
documents: one with <books> and the other with <magazines> as its root element.
The output of this example will not be well-formed XML because of the two root elements, so
the client might refuse to process it. However, it is still a legal JSP document.
In addition to including JSP documents in JSP documents, you can also include JSP pages
written in standard syntax in JSP documents, and you can include JSP documents in JSP pages
written in standard syntax. The container detects the page you are including and parses it as
either a standard syntax JSP page or a JSP document and then places it into the XML view for
validation.
Creating Static and Dynamic Content
This section explains how to represent static text and dynamic content in a JSP document. You
can represent static text in a JSP document using uninterpreted XML tags or the jsp:text
element. The jsp:text element passes its content through to the output.
If you use jsp:text, all white space is preserved. For example, consider this example using
XML tags:
<books>
<book>
Web Servers for Fun and Profit
</book>
</books>
The output generated from this XML has all white space removed:
<books><book>
Web Servers for Fun and Profit
</book></books>
If you wrap the example XML with a <jsp:text> tag, all white space is preserved. The white
space characters are #x20, #x9, #xD, and #xA.
You can also use jsp:text to output static data that is not well formed. The ${counter}
expression in the following example would be illegal in a JSP document if it were not wrapped
in a jsp:text tag.
<c:forEach var=
"counter" begin="1" end="${3}">
<jsp:text>${counter}</jsp:text>
</c:forEach>
This example will output
Creating a JSP Document
Chapter 6 · JavaServer Pages Documents
193