JSP expression tag

JSP expression tag

The code written inside JSP expression tag is put into the bracket of  print() method . So you need not write out.print() to write data. The code written inside JSP expression tag are place into Service method of generated Servlet . It is mainly used to print the values of variable and  method.

Syntax of Expression Tag

<%= JavaExpression %>

When the Container sees this

<%= "Hello" %>

It puts into print() method 

out.print("Hello");

Note: Never end an expression with semicolon inside Expression Tag.

<%= "Hello"; %> Never end an expression with semicolon

Example of Expression Tag

<html>
    <head>
        <title>My First JSP Page</title>
    </head>
   <%
       int count = 0;
   %>
  <body>
        Page Count is  <%= ++count %>   
  </body

Leave a comment