The JSP expression can contain any valid scripting language expression that will be evaluated. The JSP expression is used for printing the values of variables or methods. We can add any statement of the java programming language in an expression tag and which can be used as an argument in the method out. println (). It should be noted here that an expression inside the expression tag must never be ended with a semi colon that is <% = (3*4); %> is invalid.
The following is the syntax of a JSP expression tag:
<%= statement %>
Consider the following example to demonstrate the use of JSP expression tag:
< html >
< body >
<%= My JSP Page %>
</ body >
</ html >
When we are using the expression tag to print something then there is no need to use out. print (). In the above code we have displayed “First JSP Page” by using the expression tag of JSP.
Consider the following line of code in which two numbers are multiplied inside an expression tag:
<% = (3*4) %>
This line is translated by the container as follows:
out. println ((3*4));