O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

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

5.5. Creating a JSP from Scratch as a JSP Document

Problem

You want to create a JSP document in an XML editor's tool.

Solution

Open up your XML editor of choice and create the JSP using only XML elements.

Discussion

A JSP document is a namespace-aware, well-formed XML file that contains JSP standard actions (such as jsp:include and jsp:useBean), custom actions (such as JSTL custom tags), and the XML equivalents of JSP directives. Table 5-1 specifies the XML equivalents for common JSP directives. Write the JSP document in an XML editor, preferably one where you can check its well-formedness. The JSP document has to be a well-formed XML document to be eligible for placement into a JSP container and execution.

Table 5-1. XML equivalents for JSP directives

Directive

Example

JSP document equivalent

page

<%@ page import="java.util.Date" %>

<jsp:directive.page import="java.util.Date" />

include

<%@ include file="footer.html" %>

<jsp:directive.include file="footer.html" />

taglib

<%@ taglib uri="WEB-INF/tlds/xml_gen.tld" prefix="t" %>

<jsp:root jsp:id="0" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" xmlns:t="urn:jsptld:/WEB-INF/tlds/xml_gen.tld">

Tip

In JSP 1.2, the only way to identify a JSP page as XML is by having a jsp:root element as the root. However, JSP 2.0 offers several new options—the JSP 2.0 specification states that a JSP document can also be distinguished from a JSP in non-XML syntax by a jsp-property-group element in the deployment descriptor, ...

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