JSP Expression

Expression is a type of JSP element which is used to embed Java code in JSP. Container takes the argument of expression (everything written between <%=  %>) and put it in as the argument to PrintWriter out which will print on JSP.

Syntax

<%=           scripting-expression            %>

Note* : Semicolon inside expression is not allowed.

Example:

<%= new java.util.Date() %>

Will be converted to

out.println(new java.util.Date());

Above expression can be added to any of JSP. These expressions will be evaluated at run time.

 

Important Point

  • Semicolon is not required while providing statement in Expression.   <%= method(); %> is incorrect
  • Method passed to Expression must return something(Not Void return type) else it will throw an error.

Leave A Comment

Your email address will not be published. Required fields are marked *