ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Writing JSPs in XML using JSP 1.2
Pages: 1, 2

Page Directive

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.



JSP syntax:

<%@ page page_directive_attr_list %>

XML syntax:

<jsp:directive.page page_directive_attr_list /> 

Include Directive

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.

JSP syntax:

<%@ include file="relativeURL" %>

XML syntax:

<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.

Declaration Element

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).

JSP syntax:

<%! declaration(s) %> 

XML syntax:

<jsp:declaration>declaration(s)</jsp:declaration>

Scriptlet Element

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.

JSP syntax:

<% code fragment %>

XML syntax:

<jsp:scriptlet>code fragment</jsp:scriptlet>

Expression Element

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.

JSP syntax:

<%= expression %>

XML syntax:

<jsp:expression>expression</jsp: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:

  • jsp:useBean
  • jsp:setProperty
  • jsp:getProperty
  • jsp:include
  • jsp:forward
  • jsp:plugin

Text Element

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 xsl:text element.

Summary

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.