JSP Quick Reference Card
Default scripting language
The scripting language of a JSP page defaults to Java.Insert the following line in a JSP page to configure thepage to use JavaScript:
<%@ page language = "javascript" %>
Using white space
White space contained within the template code isreturned to the client as it was entered in the JSP.
Quoting attribute values
Quote attribute values, using either single or doublequotes, to all JSP elements. For example:
<%@ page contentType = "
text/plain
" %>
Writing comments for the JSP
A JSP comment is not output to the client as part of theJSP page’s output.
<%--
Co mme n t s t r i n g
... --%>
Outputting comments to the client
HTML comments are output to the client.
<!--
c o mme n t s
-->
page
Defines page-wide attributes.
<%@page
a t t r i b u t e
="
v a l u e
" ... %>
a t t r i b u t e s
, with default values, are:
a t t r i b u t e
= language="java" | session="true"| contentType=text/html;charset="ISO-8859-1"| import="
p a c k a g e ( s )
" | buffer="8kb"| autoflush="true" | isThreadSafe="true"| info="text_string" | errorPage="
r e l a t i v e URL
"| isErrorpage="true" | extends="
c l a s s _ n a me
"
v a l u e
= a string literal in single or double quotes.
include
Inserts text into a JSP page.
<%@include file = "path" ... %>
taglib
Defines a custom tag library used by a JSP page.
<%@taglib uri="
t a g L i b r a r y URI
"prefix="
t a g Pr e f i x
" %>
After the
taglib
directive, reference the custom tagsusing the syntax:
<
t a g Pr e f i x
:
t a g Na me
>...</
t a g Pr e f i x
:
t a g Na me
>
declaration
Creates page-wide definitions such as variables.
<%! declaration %>
Example:
<%!private String foo = null;public String getFoo() {return this.foo;} %>
scriptlet
Contains a block of scripting code. A JSP page cancontain multiple blocks of scripting code.
<% script
c o d e
%>
Example:
<%String greeting =request.getParameter("Greeting");out.println(greeting); %>
expression
Defines statements evaluated on the server beforesending the page output to the client.
<%= expression %>
Example:
<%= myVar1%>
jsp:include
Call one JSP page from another. Upon completion, thedestination page returns control to the calling page.
<jsp:include page="
p a t h
" flush="true"/><jsp:include page="
p a t h
" flush="true"><jsp:param name="
p a r a mNa me
"value="
p a r a mVa l u e
" /> ...</jsp:include>
jsp:forward
Calls one JSP page from another. Execution of the calling page is terminated by the call.
<jsp:forward page="
p a t h
" /><jsp:forward page="
p a t h
"><jsp:param name="
p a r a mNa me
"value="
p a r a mVa l u e
" /> ...</jsp:forward>
Basic SyntaxDirectivesScripting ElementsActions
Add a Comment