JSP | Expression tag

Last Updated : 14 May, 2026

The Expression Tag in JSP is used to display output directly on the client’s browser. It allows embedding Java expressions inside a JSP page and automatically converts them into string output. This tag simplifies printing data without writing explicit output statements.

  • Uses <%= %> syntax to write Java expressions
  • Automatically prints output to the browser (no need for out.print())
  • Mainly used for displaying data, not for writing logic

Syntax:

<%= expression %>

Difference from Scriptlet Tag

  • Scriptlet (<% %>) → used for writing Java logic (loops, conditions)
  • Expression (<%= %>) → used for displaying output
  • Expression tag automatically converts into out.print()

Example 

html
<html>  
<body>  
<%= GeeksforGeeks %>  <!-- Expression tag -->
</body>  
</html>

Explanation: In this example, the string "Welcome to GeeksforGeeks" will be printed directly in the client's browser.

Output

out
output

Implementation of JSP Expression Tag

Step 1: Create Dynamic Web Project

  • Go to File -> New -> Dynamic Web Project
  • Project Name: Geeks
  • Select Apache Tomcat
  • Click Finish

Step 2: Create index.html.

This HTML file takes the username from the user and sends it to Geeks.jsp on form submission

HTML
<!--index.html -->
<!-- Example of JSP code which prints the Username -->
<html>
<body>
<form action="Geeks.jsp">
<!-- move the control to Geeks.jsp when Submit button is click -->

Enter Username:
<input type="text" name="username">
<input type="submit" value="Submit"><br/>

</form>
</body>
</html>

Output:

output
output

Step 3: Create JSP File

Here we are creating a jsp file names as Geeks.jsp

HTML
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>Insert title here</title>
</head>

<body>
<%= String name=request.getParameter("username");
out.print("Hello "+name);
%>
</body>

</html>

Explanation:

  • <%@ page ... %>: Sets page settings (Java language, UTF-8 encoding).
  • request.getParameter("username"): Retrieves the username entered in the HTML form.
  • <% ... %>: Used for writing Java code (e.g., storing the username in a variable).
  • <%= name %>: Outputs the value of name to the browser (auto-converted to out.print()).

If user enters Geeks, it displays: Hello Geeks!

Output: 

output
output
Comment