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 O’Reilly online learning.

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