JSP Quick Reference Card
JSP Quick Reference Card
2
Element Description JSP Syntax XML
Legend All tags are case sensitive. A pair of single quotes is equivalent to a pair of double quotes. Spaces are not allowed between an equals sign and an attribute value. plain text = required [ ] = optional Notes bold = default { } = required choice italics = user-defined ... = list of items | = or + = can repeat
1. JSP and XML syntax cannot be mixed within a page. 2. A page in one syntax can include or forward to a page in the other syntax. 3. Some action elements have attributes whose value can be computed at request time. In JSP syntax, the format of such a value is the same as a JSP expression: <%= expression %>. In XML syntax, the format of the value is %= expression %. No equivalent. <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" [xmlns:taglibPrefix="URI"]+ ... version="1.2"> other elements </jsp:root No equivalent. <jsp:declaration> declaration [ declaration; ]+ ... </jsp:declaration <jsp:expression> expression </jsp:expression> <jsp:scriptlet> code fragment </jsp:scriptlet> <jsp:text> template data </jsp:text> XML syntax allows an XML element that does not represent a standard or custom action to appear anywhere a jsp:text can appear. Such an element is passed to the current out.
Root
Comment
Documents the JSP file, but is not included in the response. Declares variables or methods valid in the pages scripting language. Contains an expression valid in the pages scripting language. Contains a code fragment valid in the pages scripting language. Encloses template data
Declaration
Expression
Scriptlet
Text
No equivalent.
Includes a file, parsing the files JSP elements. Defines attributes that apply to a JSP page.
<%@ include file="relativeURL" %> <%@ page [ language="java" ] [ extends="package.class" ] [ import="{package.class | package.*} , ... " ] [ session="true|false" ] [ buffer="none| 8kb|sizekb" ] [ autoFlush="true|false" ] [ isThreadSafe="true|false" ] [ info="text" ] [ errorPage="relativeURL" ] [ isErrorPage="true| false" ] [ contentType="{mimeType [ ; charset=characterSet ] | text/html ; charset=ISO-8859-1}" ] [ pageEncoding="{characterSet | ISO-8859-1}" ] %> <%@ taglib uri="URI" prefix="tagPrefix" %> <tagPrefix:name attribute="value"+ ... /> | <tagPrefix:name attribute="value"+ ... > other tags and data </tagPrefix:name> <jsp:forward page="{relativeURL | <%= expression %> }" { /> | > [ <jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" /> ] + </jsp:forward> } <jsp:getProperty name="beanInstanceName" property="propertyName" /> <jsp:include page="{relativeURL | <%= expression %>}" [ flush="true | false" ] { /> | > [ <jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" /> ] + </jsp:include> }
<jsp:directive.include file="relativeURLspec" /> <jsp:directive.page pageDirectiveAttrList /> where pageDirectiveAttrList is the same as the list in the JSP column.
Page Directive
Taglib Directive
Defines a tag library and prefix for custom tags used in the JSP page. Accesses a custom tags functionality.
No equivalent. Included in Root <tagPrefix:name attribute="value"+ ... /> | <tagPrefix:name attribute="value"+ ... > other tags and data </tagPrefix:name> <jsp:forward page="{relativeURL | %= expression % }" { /> | > [ <jsp:param name="parameterName" value="{parameterValue | %= expression %}" /> ] + </jsp:forward> } <jsp:getProperty name="beanInstanceName" property="propertyName" /> <jsp:include page="{relativeURL | %= expression %}" [ flush="true | false" ] { /> | > [ <jsp:param name="parameterName" value="{parameterValue | %= expression %}" /> ] + </jsp:include> }
<tagPrefix:name>
<jsp:forward>
<jsp:getProperty>
Inserts the value of a bean property into the result. Includes a static file or the result from another web component.
<jsp:include>
2001 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems, the Sun logo, Java, the Java Coffee Cup logo, JavaServer Pages, and the Duke logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
Causes the execution of an applet or bean. The applet or bean executes in the specified plugin. If the plugin is not available, displays a dialog to initiate the download of the plugin software.
<jsp:plugin type="bean|applet" code="classFileName" codebase="classFileDirectoryName" [ name="instanceName" ] [ archive="URIToArchive, ..." ] [ align="bottom|top|middle|left|right" ] [ height="{displayPixels | <%= expression %>}" ] [ width="{displayPixels | <%= expression %>}"] [ hspace="leftRightPixels" ] [ vspace="topBottomPixels" ] [ jreversion="JREVersionNumber | 1.2" ] [ nspluginurl="URLToPlugin" ] [ iepluginurl="URLToPlugin" ] > [ <jsp:params> [ <jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" /> ]+ </jsp:params> ] [ <jsp:fallback> text message if plugin download fails </jsp:fallback> ] </jsp:plugin> <jsp:setProperty name="beanInstanceName" { property="*" | property="propertyName" [ param="parameterName" ] | property="propertyName" value="{string | <%= expression %>}" } /> <jsp:useBean id="beanInstanceName" scope="page|request|session|application" { class="package.class" [ type="package.class" ] | beanName="{package.class | <%= expression %>}" type="package.class" | type="package.class" } { /> | > other elements </jsp:useBean> }
<jsp:plugin type="bean|applet" code="classFileName" codebase="classFileDirectoryName" [ name="instanceName" ] [ archive="URIToArchive, ..." ] [ align="bottom|top|middle|left|right" ] [ height="{displayPixels | %= expression %}" ] [ width="{displayPixels | %= expression %}"] [ hspace="leftRightPixels" ] [ vspace="topBottomPixels" ] [ jreversion="JREVersionNumber | 1.2" ] [ nspluginurl="URLToPlugin" ] [ iepluginurl="URLToPlugin" ] > [ <jsp:params> [ <jsp:param name="parameterName" value="{parameterValue | %= expression %}" /> ]+ </jsp:params> ] [ <jsp:fallback> text message if plugin download fails </jsp:fallback> ] </jsp:plugin> <jsp:setProperty name="beanInstanceName" { property="*" | property="propertyName" [ param="parameterName" ] | property="propertyName" value="{string | %= expression %}" } /> <jsp:useBean id="beanInstanceName" scope="page|request|session|application" { class="package.class" [ type="package.class" ] | beanName="{package.class | %= expression %}" type="package.class" | type="package.class" } { /> | > other elements </jsp:useBean> }
<jsp:setProperty>
<jsp:useBean>
2001 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems, the Sun logo, Java, the Java Coffee Cup logo, JavaServer Pages, and the Duke logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
Subclass of javax.servlet.ServletRequest Subclass of javax.servlet.ServletResponse javax.servlet.jsp.PageContext javax.servlet.http.HttpSession javax.servlet.ServletContext javax.servlet.jsp.JspWriter javax.servlet.ServletConfig java.lang.Object java.lang.Throwable
getAttribute, getParameter, getParameterNames, getParameterValues, setAttribute Not typically used by JSP page authors findAttribute, getAttribute, getAttributesScope, getAttributeNamesInScope, setAttribute getAttribute, getId, setAttribute getAttribute, getMimeType, getRealPath, setAttribute clear, clearBuffer, flush, getBufferSize, getRemaining getInitParameter, getInitParameterNames Not typically used by JSP page authors getMessage, getLocalizedMessage, printStackTrace, toString
2001 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems, the Sun logo, Java, the Java Coffee Cup logo, JavaServer Pages, and the Duke logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.