Scriptlet
Contains a code fragment valid in the page scripting language.
JSP Syntax
<%code fragment%>
<jsp:scriptlet> code fragment </jsp:scriptlet>
XML Syntax
<jsp:scriptlet> code fragment </jsp:scriptlet>
Examples
<%
String name = null;
if (request.getParameter("name") == null) {
%>
<%@ include file="error.html" %>
<%
} else {
foo.setName(request.getParameter("name"));
if (foo.getName().equalsIgnoreCase("integra"))
name = "acura";
if (name.equalsIgnoreCase( "acura" )) {
%>
Description
A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.
Within a scriptlet, you can do any of the following:
- Declare variables or methods to use later in the JSP page (see also Declaration).
- Write expressions valid in the page scripting language (see also Expression).
- Use any of the implicit objects or any object declared with a
<jsp:useBean>element. - Write any other statement valid in the scripting language used in the JSP page.
Any text, HTML tags, or JSP elements you write must be outside the scriptlet.
Scriptlets are executed at request time, when the JSP container processes the request. If the scriptlet produces output, the output is stored in the out object.
