Stage 2 · Topic 2 - JSP · Session 1: Elements and Directives
| 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 |
| Directive | Syntax | Purpose |
|---|---|---|
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) |