Expression
Expression tag is used to display java expression output of any data on the generated page.
The data placed in Expression tag prints on the output stream and automatically converts data into string.
The Expression tag can contain any Java expression used for printing output equivalent to out.println().
Syntax :
<%= java expression %> |
Example:
Test.jsp | Test_java.java |
Ex: <%= 10 %> | out.println(10) |
Case 1:
In side expression we can’t take semicolon otherwise we will get http status 500.
Ex1 : test.jsp
<%@ page import="java.util.*"%> <h2><%= new Date();%></h2> |
Output:
Ex2 : test.jsp
<%@ page import="java.util.*"%> <h2><%= new Date()%></h2> |
Output:
Case 2:
Within the expression we can take method calls also but void return type method calls are not allowed.
<%@ page import="java.util.*"%> <%= Math.random() %> <%= new java.util.ArrayList().clear() %> |
Output:
We can’t place space between percentage and equal inside expression tag otherwise compile time error with 500 status code (because it is treated as scriptlet.
Ex:
<%@ page import="java.util.*"%> <% = new Date() %> |
<% = 10 %>
It treated as scriptlet code so “= 10 ” is not a valid java statement.
Output:
No comments:
Post a Comment