JSP Quick Reference Card
JSP Quick Reference Card
Directives
page
Defines page-wide attributes.
<%@ page attribute="value" ... %> attributes, with default values, are:
Contains a block of scripting code. A JSP page can contain multiple blocks of scripting code.
<% script code %>
Example:
<% String greeting = request.getParameter("Greeting"); out.println(greeting); %>
attribute = language="java" | session="true" | contentType=text/html;charset="ISO-8859-1" | import="package(s)" | buffer="8kb" | autoflush="true" | isThreadSafe="true" | info="text_string" | errorPage="relativeURL" | isErrorpage="true" | extends="class_name" value = a string literal in single or double quotes.
expression
Defines statements evaluated on the server before sending the page output to the client.
<%= expression %>
Example:
<%= myVar1%>
include
Inserts text into a JSP page.
<%@ include file = "path" ... %>
Actions
jsp:include
Call one JSP page from another. Upon completion, the destination page returns control to the calling page.
<jsp:include page="path" flush="true"/> <jsp:include page="path" flush="true"> <jsp:param name="paramName" value="paramValue" /> ... </jsp:include>
taglib
Defines a custom tag library used by a JSP page.
<%@ taglib uri="tagLibraryURI" prefix="tagPrefix" %>
After the taglib directive, reference the custom tags using the syntax:
<tagPrefix:tagName> ... </tagPrefix:tagName>
jsp:forward
Scripting Elements
declaration
Creates page-wide definitions such as variables.
<%! declaration %>
Calls one JSP page from another. Execution of the calling page is terminated by the call.
<jsp:forward page="path" /> <jsp:forward page="path"> <jsp:param name="paramName" value="paramValue" /> ... </jsp:forward>
Example:
<%! private String foo = null; public String getFoo() {return this.foo;} %>
jsp:plugin
Enables you to invoke an applet on a client browser.
<jsp:plugin type="bean|applet" code="objectCode" codebase="objectCodebase" { align="alignment" } { archive="archiveList" } { height="height" } { hspace="hspace" } { jreversion="jreversion" } { name="componentName" } { vspace="vspace" } { width="width" } { nspluginurl="url" } { iepluginurl="url" } > { <jsp:params> { <jsp:param name=" paramName" value="paramValue" /> }+ </jsp:params> } { <jsp:fallback> arbitrary_text </jsp:fallback> } > </jsp:plugin>
jsp:setProperty
Sets the value of one or more properties in a bean.
<jsp:setProperty name="beanName" prop_expr />
pageContext
The page context for the JSP. Java type: javax.servlet.jsp.PageContext
prop_expr has one of the following forms: property="*" | property="propertyName"| property="propertyName" param="parameterName"| property="propertyName" value="propertyValue"
request
The client request. Java type: javax.servlet.HttpServletRequest
jsp:getProperty
Writes the value of a bean property as a string to the out object.
<jsp:getProperty name="name" property="propertyName" />
response
The response to the client. Java type: javax.servlet.HttpServletResponse
session
The session object created for the requesting client. Java type: javax.servlet.http.HttpSession
JSP Objects
See the corresponding Java object type for the available methods for these objects.
application
The servlet context obtained from the servlet configuration object. Java type: javax.servlet.ServletContext
jsp:useBean
Defines an instance of a Java bean.
<jsp:useBean id="name" scope="page|request|session|application" typeSpec /> <jsp:useBean id="name" scope="page|request|session|application" typeSpec > body </jsp:useBean>
config
The ServletConfig object for the JSP page. Java type: javax.servlet.ServletConfig
exception
The uncaught exception that resulted in the error page being invoked. Java type: java.lang.Throwable
out
An object that writes into a JSP pages output stream. Java type: javax.servlet.jsp.JspWriter