A.10. JSP Scripting Elements

Types of Scripting Elements

  • Expressions: <%= expression %>

    Evaluated and inserted into servlet's output. You can also use

    <jsp:expression>
    expression
    </jsp:expression>
    
  • Scriptlets: <% code %>

    Inserted into servlet's _jspService method (called by service). You can also use

    <jsp:scriptlet>
    code
    </jsp:scriptlet>
    
  • Declarations: <%! code %>

    Inserted into body of servlet class, outside of any existing methods. You can also use

    <jsp:declaration>
    code
    </jsp:declaration>
    

Template Text

  • Use <\% to get <% in output.

  • <%-- JSP Comment --%>

  • <!-- HTML Comment -->

  • All other non-JSP-specific text passed through to output page.

Predefined Variables

Implicit objects automatically available in expressions and scriptlets (not declarations).

Get Core Servlets and JavaServer Pages™ 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.