Show TOC

Syntax Elements OutlineLocate this document in the navigation structure

Use

There are two JSP formats: JSP pages in standard format and JSP documents. JSP pages in standard format contain any type of text or markup. JSP documents are XML documents containing XHTML and JSP elements. The Web Container processes a JSP page as a JSP document if one of the following conditions is true:

  • The request path matches the URL pattern for a web.xml JSP property group declaration with an <is-xml> element set to true .

  • The request path extension is .jspx, unless this extension matches the URL pattern for a JSP property group declaration with an <is-xml> element set to false . In other words, .jspx is the default extension for JSP Documents, but it can be explicitly disabled by a property group declaration.

  • The request path extension is either .jsp or matches a URL pattern for a JSP property group declaration and the root element in the file is <jsp:root> .

The following table lists the JSP elements with their JSP and XML syntax:

JSP Element

Syntax

XML Syntax

Description

Template text

text

<jsp:text>text</jsp:text> <hello>This is an ordinary XML tag </hello> <br/>

Directly written to client output.

JSP Comment

<%-- comment --%>

<jsp:text>text</jsp:text><hello>This is an ordinary XML tag </hello> <br/>

 

JSP Expression

<%= expression %>

<jsp:expression>expression</jsp:expression>

Expression is evaluated and written to output.

JSP Scriptlet

<% code %>

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

Code is inserted in service method.

JSP Declaration

<%! code %>

<jsp:declaration>code</jsp:declaration>

Code is inserted in body of servlet class, outside of service method.

JSP page Directive

<%@ page att="val" %>

<jsp:directive.page att="val"/>

Directions to the servlet engine about general setup

JSP Actions

<jsp:actionName/>

<jsp:actionName/>

Several well known actions. Defined in the specification

Custom Actions

<my:action/>

<my:action/>

User-defined actions

Expression Language

${expr}

#{expr}

${expr}

#{expr}

Expression language expressions.