JSP Syntax

Code Scriptlets

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

Example:

<%
   for (int i=0; i < 10; i++)
   {
        out.println("Hello");
   }
%>
						

Expressions

The <%= %> tags enclose an expression whose value is inserted into the output stream.

Example:

Welcome back, <%= getFirstName() %>!

Declarations

The <%! %> tags enclose a series of declarations that are placed outside the main service method.

Example:

<%!
    public String getFirstName()
    {
        Person pers = (Person) session.getAttribute("person");
        return pers.firstName;
    }
%>
						

Comments

The <%-- --%> tags enclose comment text. The JSP compiler completely ignores the comment text. Comments ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.