About JSP Syntax

See Also

JSP files have four main characteristics:

You can compose a JSP page using either standard JSP syntax or JSP document syntax.

tip  You can use the web.xml Visual Editor to group a set of JSP files and redefine them as JSP documents. This has a variety of consequences. For example, a JSP file's page encoding is interpreted differently to that of a JSP document.

This topic first describes standard JSP syntax and then describes JSP document syntax. Whether you use standard JSP syntax or JSP document syntax, the JSP Source Editor provides code completion and syntax coloring facilities to help you construct a valid JSP page.

Standard JSP Syntax

JSP Element Syntax

The three types of JSP elements are:

JSP syntax is similar to XML. Action elements have a start tag, including the element name, possibly with attributes, an optional body, and a matching end tag. For example:

<mytag1 attr1="attribute value" ...>...</mytag1>

or

<mytag2 attr1="attribute value" .../../../../../../../../>

JSP tags are case-sensitive, as in XML and XHTML.

Start and End Tags

Elements that have distinct start and end tags with an enclosed body must start and end in the same file. You cannot begin a tag in one file and end that tag in another file. This rule also applies to elements in the alternate syntax. For example, a scriptlet has the syntax <% scriptlet %>. Both the opening <% delimiter and the closing %> delimiter must be in the same physical file.

Empty Elements

Following the XML specification, an element described using an empty tag is indistinguishable from an element using a start tag, an empty body, and an end tag.

Attribute Values

Attribute values always appear quoted. Both single and double quotes can be used. The entities &apos; and &quot; are available to describe single and double quotes in output text. You can also use \" and \' within quoted text.

Comments Within JSP Files

The syntax for comments within JSP files is as follows:

<%-- and --%>

JSP Document Syntax

A JSP document is a JSP page that is written using XML syntax. A JSP file identifies itself as a JSP document using one of the following methods:

JSP Document Elements

A JSP document can contain the following elements:

For more information about JSP syntax and JSP document syntax, see JavaServer Pages Specification Version, available at

See Also
Compiling a JSP File
About JavaServer Pages Technology
About JSP Character Encoding

Legal Notices