0% found this document useful (0 votes)
2 views

java

The document explains JSP (JavaServer Pages) Expression and Scriptlet tags. Expression tags, denoted by <%= %>, are used to insert Java expressions directly into HTML output, while Scriptlet tags, denoted by <% %>, allow for the inclusion of Java code such as control statements and loops. Examples are provided to demonstrate the use of both tags in displaying values and performing calculations.

Uploaded by

introvertb46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java

The document explains JSP (JavaServer Pages) Expression and Scriptlet tags. Expression tags, denoted by <%= %>, are used to insert Java expressions directly into HTML output, while Scriptlet tags, denoted by <% %>, allow for the inclusion of Java code such as control statements and loops. Examples are provided to demonstrate the use of both tags in displaying values and performing calculations.

Uploaded by

introvertb46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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>

You might also like