Oracle JavaServer Pages Developer's Guide and Reference
Release 8.1.7

Part Number A83726-01





Go to previous page Go to beginning of chapter Go to next page

Overview of JSP Syntax Elements

You have seen a simple example of JSP syntax in "What a JSP Page Looks Like"; now here is a top-level list of syntax categories and topics:

This section introduces each category, including basic syntax and a few examples. For more information, see the Sun Microsystems JavaServer Pages Specification, Version 1.1.


There are XML-compatible alternatives to the syntax for JSP directives, declarations, expressions, and scriptlets. See "XML-Alternative Syntax".  


Directives provide instruction to the JSP container regarding the entire JSP page. This information is used in translating or executing the page. The basic syntax is as follows:

<%@ directive attribute1="value1" attribute2="value2"... %>

The JSP 1.1 specification supports the following directives:

Scripting Elements

JSP scripting elements include the following categories of snippets of Java code that can appear in a JSP page:

JSP Objects and Scopes

In this document, the term JSP object refers to a Java class instance declared within or accessible to a JSP page. JSP objects can be either:


Scopes are discussed below, in "Object Scopes".

Explicit Objects

Explicit objects are typically JavaBean instances declared and created in jsp:useBean action statements. The jsp:useBean statement and other action statements are described in "JSP Actions and the <jsp: > Tag Set", but an example is also shown here:

<jsp:useBean id="pageBean" class="mybeans.NameBean" scope="page" />

This statement defines an instance, pageBean, of the NameBean class that is in the mybeans package. The scope parameter is discussed in the next section, "Object Scopes".

You can also create objects within Java scriptlets or declarations, just as you would create Java class instances in any Java program.

Object Scopes

Objects in a JSP, whether explicit or implicit, are accessible within a particular scope. In the case of explicit objects, such as a JavaBean instance created in a jsp:useBean action statement, you can explicitly set the scope with the following syntax (as in the example in the preceding section, "Explicit Objects"):


There are four possible scopes:

Implicit Objects

JSP technology makes available to any JSP page a set of implicit objects. These are Java class instances that are created automatically by the JSP mechanism and that allow interaction with the underlying servlet environment.

The following implicit objects are available. For information about methods available with these objects, refer to the Sun Microsystems Javadoc for the noted classes and interfaces at the following location:

Using an Implicit Object

Any of the implicit objects discussed in the preceding section may be useful. The following example uses the request object to retrieve and display the value of the username parameter from the HTTP request:

<H3> Welcome <%= request.getParameter("username") %> ! <H3>

JSP Actions and the <jsp: > Tag Set

JSP action elements result in some sort of action occurring while the JSP page is being executed, such as instantiating a Java object and making it available to the page. Such actions may include the following:

Action elements use a set of standard JSP tags that begin with <jsp: syntax. Although the tags described earlier in this chapter that begin with <% syntax are sufficient to code a JSP page, the <jsp: tags provide additional functionality and convenience.

Action elements also use syntax similar to that of XML statements, with similar "begin" and "end" tags such as in the following example:

<jsp:sampletag attr1="value1" attr2="value2" ... attrN="valueN">

Or, where there is no body, the action statement is terminated with an empty tag:

<jsp:sampletag attr1="value1", ..., attrN="valueN" />

The JSP specification includes the following standard action tags, which are introduced and briefly discussed here:

Tag Libraries

In addition to the standard JSP tags discussed previously in this section, the JSP specification lets vendors define their own tag libraries and also lets vendors implement a framework allowing customers to define their own tag libraries.

A tag library defines a collection of custom tags and can be thought of as a JSP sub-language. Developers can use tag libraries directly, in manually coding a JSP page, but they might also be used automatically by Java development tools. A tag library must be portable between different JSP container implementations.

Import a tag library into a JSP page using the taglib directive, introduced in "Directives".

Key concepts of standard JavaServer Pages support for JSP tag libraries include the following topics:

For information about these topics, see "Standard Tag Library Framework".

For information about the sample tag library provided with OracleJSP, see "Overview of the JSP Markup Language (JML) Sample Tag Library"

For further information, see the Sun Microsystems JavaServer Pages Specification, Version 1.1.

Go to previous page
Go to beginning of chapter
Go to next page
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.