Writing JSPs in XML using JSP 1.2
Pages: 1, 2
The page directive is used to define a number of page-dependent properties and pass these values to the container. This element must appear at the beginning of the JSP document.
<%@ page page_directive_attr_list %>
<jsp:directive.page page_directive_attr_list />
The include directive is used to substitute text and/or code at JSP translation time. A JSP in either syntax can use the include directive to include another JSP written in either syntax. This element can appear anywhere within a JSP document.
<%@ include file="relativeURL" %>
<jsp:directive.include file="relativeURL" />
An interesting point to make: the XML view of a JSP page does not contain
jsp:directive.include elements; rather, the included file is expanded in place. This is done to simplify validation.
The declaration element is used to declare scripting-level constructs that are available to all other scripting elements. This element does not have any attributes and the body of the element is the declaration(s).
<%! declaration(s) %>
The scriplet element is used to insert fragments of code. This element does not have any attributes and the body of the element is the program fragment.
<% code fragment %>
The expression element is used to describe complete expressions that get evaluated at run-time. This element does not have any attributes and the body of the element is the expression.
<%= expression %>
Standard and Custom Actions
The standard and custom action elements were defined in XML syntax prior to the 1.2 specification. Just as a reminder, the standard actions include:
The text element is used to enter template data into a JSP document. This element does not have any attributes and the body of the element is the template data. The XML syntax of this element is:
<jsp:text>template data</jsp:text>. When this element is interpreted, the body is passed through to the current value of
out. This element is very similar to the XSLT
JSP documents provide many benefits, including the ability to validate JSPs and to manipulate them with XML-aware tools. They behave the same way a traditional JSP does, by generating a response stream of characters from template data and dynamic data. JSP documents even contain many of the same types of elements, just now in XML syntax. This is one of the great additions to the JSP 1.2 specification, and I think it will play more and more of a role as the specification and developer community mature.
Stephanie Fesler is a BEA Systems expert on implementing various Java 2EE API.
Return to ONJava.com.