Share on Google+Share on Google+

JSPs : Expressions

Advertisement
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 :

Advertisements

Posted on: December 3, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.