20.3. JSP Scripting Elements

JSP scripting elements let you insert code into the servlet that will be generated from the JSP page. There are three forms:

  1. Expressions of the form <%= expression %>, which are evaluated and inserted into the servlet's output

  2. Scriptlets of the form <% code %>, which are inserted into the servlet's _jspService method (called by service)

  3. Declarations of the form <%! code %>, which are inserted into the body of the servlet class, outside of any existing methods

Each of these scripting elements is described in more detail in the following sections.

In many cases, a large percentage of your JSP page just consists of static HTML, known as template text. In almost all respects, this HTML looks just like normal HTML, follows ...

Get Core Web Programming, Second 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.