Slide 2 — the scripting elements provide the ability to insert java code inside a JSP. There are exactly three of them.
Element Syntax Becomes Use it for
Scriptlet
<% %>
<% java code %> statements inside _jspService() loops, conditions, local variables, request.getParameter(), anything that needs out.print()
Expression
<%= %>
<%= statement %> out.print(statement) printing one value; no out.print() needed, no semicolon allowed
Declaration
<%! %>
<%! field or method %> a field or method of the servlet class, outside _jspService() helper methods, constants. Almost never for state — use a scope instead

And the three directives

DirectiveSyntaxPurpose
page <%@ page attribute="value" %> attributes that apply to the whole page: import, contentType, pageEncoding, buffer, info, errorPage, isErrorPage, isELIgnored …
include <%@ include file="resourceName" %> paste a static resource into this page at translation time
taglib <%@ taglib uri="uriOfTagLibrary" prefix="prefix" %> declare a tag library so its tags may be used (see Session 3 and Session 5)

← Back to the example index