Expression Tag
Expression tag is used to write the response to the browser. Whatever we write within the expression tag is written on the browser. It is equivalent of out.print() statement of scriptlet tag.
Expression Tag Syntax
<%= expression %>
Expression Tag Example
<%= "This is expression Tag" %>
The above statement will print This is expression Tag on the browser. It is equivalent of the below
<% out.print("This is expression Tag"); %>
Another example
<%= "Sum of 10 and 20 = " + (10 + 20) %>
Note1 -> Please note that expression tags don’t require semicolon to end the statement.
Note2 -> We can have any number of expression tags in a jsp page.
Expression Tag example to print multiplication of two numbers
numbers.jsp
<html>
<body>
<form action="multiplication.jsp">
Number1 : <input type="text" name="num1"><br><br>
Number2 : <input type="text" name="num2">
<input type="submit" value="Multiply"><br />
</form>
</body>
</html>
multiplication.jsp
<html>
<body>
<% String num1 = request.getParameter("num1"); %>
<% String num2 = request.getParameter("num1"); %>
<%= "The result = " + Integer.valueOf(num1) * Integer.valueOf(num2) %>
</body>
</html>