JSPs : Expressions


 

JSPs : Expressions

This tutorial contains description of Expressions which is one of JSP page element.

This tutorial contains description of Expressions which is one of JSP page element.

JSPs : Expressions

This tutorial contains description of Expressions which is one of JSP page element.

Expressions :

Expressions in JSPs is used to output any data on the generated page. These data are automatically converted to string and printed on the output stream. It is an instruction to the web container for executing the code with in the expression and replace it with the resultant output content. For writing expression in JSP, you can use <%= and %> tags

Syntax :

<%= expression %>

semicolon is not permitted within a JSP expression but for same, semicolon is used for scriptlets. Expressions are checked at run time so it has access to all of the JSP implicit objects.

Example :


<%@page import="java.io.PrintWriter"%><html>
<head>
<title>Scriptlet Example</title>
</head>
<body>

<%!int a = 10;
int b = 20;%>

<%
int sum = a + b;
%>
Sum of a=
<%=a%>
and b=
<%=b%>
is :
<%=sum%>
</body>
</html>

Output :

Ads