JSP scripting elements

Scripting elements manipulate objects and perform computations. The character sequence that precedes a scripting element depends on the element’s type: <% for a scriptlet, <%= for an expression, and <%! for a declaration. Scriptlets, expressions, declarations, and server-side comments are all closed with the sequence %>.

Scriptlets

A scriptlet contains a code fragment valid in the page-scripting language (usually Java, but other languages can be defined in the page directive):

<% cart.processRequest(request); %>

Expressions

An expression contains an expression valid in the page-scripting language:

Value="<%= request.getParameter("amount") %>"

Declarations

A declaration declares variables or methods valid in the page-scripting language:

<%! Connection myconnection; String mystring; %>

Comments

You can add two types of comments to a JSP file:

To insert a comment, type it in the Source view.