JSP | ScriptletTag (original) (raw)

Last Updated : 14 May, 2026

The Scriptlet Tag in JSP is used to embed Java code directly into a JSP page. The code written inside the <% %> tag is executed on the server whenever a request is made, helping generate dynamic content. It is one of the basic scripting elements provided by JSP.

Syntax:

<%

// Java code here

%>

**Example:

Java `

<% int num = 10; out.println("Value of num is: " + num); %>

`

**Output:

Value of num is: 10

Implementation of JSP Scriptlet Tag

Step 1. Create a New Dynamic Web Project

Step 2: Create index.html file

Right-click on WebContent -> New -> Html File

Enter Username:

`

Step 3: Create Geeks.jsp file

Right-click on WebContent -> New -> JSP File

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

Insert title here <% String name=request.getParameter("username"); out.print("Hello "+name); %>

`

Run Project in Eclipse with Apache Tomcat

Right-click project ->Run As ->Run on Server (select Apache Tomcat). And access in Browser using given url.

http://localhost:8080/Geeks/

Scriptlet

output

**click submit:

tagoutput

output