Web Development with JavaServer Pages

Скачать в pdf «Web Development with JavaServer Pages»

4.1.1    Directives and scripting elements

Some JSP tags begin with the characters <% and end with %>, the same delimiters used in the ASP environment. In JSP, an additional character may appear after the leading <% to further describe the purpose of the tag.

Tags of this style have one of two purposes: either they include Java code in the JSP page, or they contain instructions for the JSP container.

How JSP works

DEFINITION If a tag introduces Java code into a JSP page, it is called a scripting element. A JSP directive, by contrast, provides instructions to the JSP container; it either requests action on the part of the container, or it specifies information about the JSP page.

The following tags are examples of scripting elements:

<%! int count = 0; %>

<%= 2 * Math.PI * radius %>


i f (radius > 10.0)    {

out.println(«Exceeds recommended maximum. Stress analysis advised.»);



Similarly, examples of directives include:

<%@ page isErrorPage=»true» %>

<%@ include file=»header.html» %>

NOTE These tags are not compatible with XML; an XML document could not contain elements that begin with <% and end with %>, with somewhat arbitrary content in between. Since JSP 1.2 allows authorship of JSP pages in XML-compliant syntax, as chapter 1 described, these tags pose a problem. JSP solves this issue by specifying a corresponding XML-compliant element for each type of non-XML tag. Chapter 5, in addition to covering the full use and functionality of directives and scripting elements, will go into further detail about the dual, XML-compliant elements.

Скачать в pdf «Web Development with JavaServer Pages»