O'Reilly logo

JavaServer Pages, Second Edition by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing JSP Pages as XML Documents

An important part of JSP 1.2 is the definition of an XML syntax for JSP. The XML syntax is primarily intended for validation and authoring tools, but it may also be of interest if you use an XML editor to develop your JSP pages. A JSP 1.2-compliant container must accept files in both the old, classic JSP 1.1 format and the new XML format, formally called a JSP Document.

A JSP Document is a namespace-aware XML document with a root element named <jsp:root> that defines the namespaces for the standard JSP elements and all tag libraries used in the page. Example 16-10 shows an example.

Example 16-10. A JSP Document (jspdocument.jsp)

                  <jsp:root 
                  xmlns:jsp="http://java.sun.com/JSP/Page" 
  xmlns:c="http://java.sun.com/jstl/core"
  version="1.2"> 
 
                  <jsp:directive.page contentType="text/html" /> 
 
  <html>
    <head>
      <title>A JSP Document</title>
    </head>
    <body bgcolor="white">
      <h1>All Request Parameters</h1>
  
      <ul> 
        <c:forEach items="${paramValues}" var="current"> 
          <li> 
            <c:out value="${current.key}" />:
            <c:forEach items="${current.value}" var="parValue">
              <br/>
              <c:out value="${parValue}" /> 
            </c:forEach>
          </li> 
        </c:forEach> 
      </ul> 
  
    </body>
  </html>
  
</jsp:root>

The <jsp:root> element has a mandatory version attribute, used to declare the version of the JSP specification. xmlns attributes declare the tag libraries used in the page. If standard actions are used, a library with the xmlns attribute value http://java.sun.com/JSP/Page must be used, as in Example 16-10. JSTL and custom ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required