Using JSP Expressions with Example

The following example illustrates using JSP expressions.
An expression is a combination of symbols that represents a value. Examples of expression include a+b, a*b, new Date() etc.
In JSP you can get an expression value and print it without the need of writing in scriptlets. The syntax is as follows


Here the result of this expression is returned as String object. If the tag alone is written in a JSP page, then the expression value is printed. In simple words, you can get the result of a function call, an arithmetic operation or an object creation using the expression.

The expression shouldn't return a void value.


    <%="This is sample text"%><br/>
    <%=new Integer(20)%><br/>
    <%="The difference is"+(20-10)%>
    This is an error, void type not allowed

Output of the program

This is sample text
The difference is10

Previous: <jsp:forward>


Posted by at on

Tags: Java Server Pages,