How to write a JSP Expression?

JSPJava 8Object Oriented ProgrammingProgramming

A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file.

Because the value of an expression is converted to a String, you can use an expression within a line of text, whether or not it is tagged with HTML, in a JSP file.

The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression.

Following is the syntax of JSP Expression −

<%= expression %>

You can write the XML equivalent of the above syntax as follows −


Following example shows a JSP Expression −

      <title>A Comment Test</title>
      <p>Today's date: <%= (new java.util.Date()).toLocaleString()%></p>

The above code will generate the following result −

Today's date: 11-Sep-2010 21:24:25

Published on 20-Mar-2019 10:30:01