10.2. JSP Expressions

A JSP expression is used to insert values directly into the output. It has the following form:

<%= Java Expression %>

The expression is evaluated, converted to a string, and inserted in the page. This evaluation is performed at run time (when the page is requested) and thus has full access to information about the request. For example, the following shows the date/time that the page was requested:

Current time: <%= new java.util.Date() %>

Predefined Variables

To simplify these expressions, you can use a number of predefined variables. These implicit objects are discussed in more detail in Section 10.5, but for the purpose of expressions, the most important ones are:

  • request, the HttpServletRequest

  • response, the HttpServletResponse ...

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.