Using the <jsp:root> Element
Most JSP Documents developed for JSP 2.0 don’t use
the <jsp:root>
element, but
it’s still supported. Potential reasons for using it
in JSP 2.0 are if you need to generate a sequence of XML documents
(i.e., the result has more than one root element) or if you want to
generate content that is not XML at all but you prefer to use XML
syntax in the JSP page (e.g., because you’re using
an XML-aware editor).
The <jsp:root>
element has a mandatory
version
attribute, and it can be used to declare
the JSP namespace and custom tag libraries used in the page with
xmlns
attributes:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" version="2.0"> ... </jsp:root>
The version
attribute value is the JSP
specification version the document complies with, and it must be
1.2
or 2.0
. Other than that, a
JSP Document with <jsp:root>
as its root
element looks just the same as the JSP Documents described earlier.
The element only serves to identify the page as a JSP Document, and
it’s not included in the response produced by the
page.
Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.