XML Syntax

JSP supports an alternate XML-compliant syntax. Although the syntax is harder to read and write, it is machine-friendly and is intended for use in automated tools.

Root Document

Every XML page requires a single root document tag. The root tag for JSP is <jsp:root>. In the <jsp:root> tag, you must include a reference to the JSP namespace.

Example:

<jsp:root xmlns:jsp="http://java.sun.com/products/jsp/dtd/jsp_1_1.dtd">

Code Scriptlets

The <jsp:scriptlet> </jsp:scriptlet> tags enclose any number of lines that is interpreted as executable code. Any code within the <jsp:scriptlet> </jsp:scriptlet> tags is placed in the main service method of the JSP.

Example:

 <jsp:scriptlet> for (int i=0; i < 10; i++) { out.println("Hello"); }</jsp:scriptlet> ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.