EXPRESSION TAGS & SCRIPLET TAGS
Submitted by, Guided by,
AISHWARYA C S Dr. NASREEN TAJ B M
4GM23IS005 Dept. of ISE
Dept. of ISE GMIT
GMIT
EXPRESSION TAGS
• An expression tag opens with <%= and is used for an expression statement whose
result replaces the expression tag when the JSP virtual engine resolves JSP tags.
An expression tags closes with %> .
• Syntax: <%= expression %>
• Used to insert the value of a Java expression directly into the output (usually
HTML).
• It is evaluated at runtime, and the result is converted to a string and inserted into
the output stream.
Expression tags to display the sum of two numbers and the current date:
<%@ page language="java"
contentType="text/html;
charset=UTF-8"
pageEncoding="UTF-8“%>
<html>
<head>
<title>JSP Expression Tag Example</title>
</head>
<body>
<h2>Using JSP Expression Tag</h2>
<p>Today's Date: <%= new java.util.Date() %></p>
<% OUTPUT:
int num1 = 10; USING JSP EXPRESSION TAG
int num2 = 20; TODAY’S DATE:MON JUN 09
14:32:10 IST 2025
%> VALUE OF NUM1:10
<p>Value of num1: <%= num1 %></p> VALUE OF NUM2:20
<p>Value of num2: <%= num2 %></p> SUM(NUM1+NUM2):30
<p>Sum (num1 + num2): <%= num1 + num2 %></p>
</body>
</html>
SCRIPLET TAGS
• A scriptlet tag opens with <% and contains commonly used Java control
statements and loops. A scriptlet tag closes with %>
• Syntax: <%
//JAVA CODE
%>
• Anything written inside <% ... %> is treated as Java code.
• You can declare variables, use loops, conditional statements, etc.
PROGRAM USING SCRIPLET TAGS
<%@ page language="java" contentType="text/html;
charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Scriptlet Example</title>
</head>
<body>
<h2>Using Scriptlet Tag in JSP</h2> OUTPUT:
<% the sum of 10 and 20 is:30
int a = 10;
int b = 20;
int sum = a + b;
%>
<p>The sum of <%= a %> and <%= b %> is: <%= sum %></p>
</body>
</html>