🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
The JSP expression tag allows developers to insert Java expressions directly into the HTML content of a JSP page. The expression is evaluated, converted to a string, and inserted into the output stream at the location of the expression tag. This tag is useful for displaying dynamic content without needing to write additional Java code in scriptlets.
The Syntax of JSP Expression Tag
<%= expression %>
How It Works
When the JSP page is processed, the expression within the <%= ... %> tag is evaluated, and the result is converted to a string and included in the HTML response sent to the client. This makes it easy to include dynamic data in the HTML output.
JSP Expression Tag Examples
Convert String to Upper Case Example
Here is a sample snippet that basically converts this string to all caps or to all upper case.
<html>
<body>
Converting a string to uppercase:
<%=new String("Hello World").toUpperCase()%>
</body>
</html>
Output:
Converting a string to uppercase: HELLO WORLD
Mathematical Expressions Example
<html>
<body>
25 multiplied by 4 equals
<%=25 * 4%>
</body>
</html>
Output:
25 multiplied by 4 equals 100
Boolean Expressions Example
<html>
<body>
Is 75 less than 69?
<%=75 < 69%>
</body>
</html>
Output:
Is 75 less than 69? false
Complete Example with Output
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Converting a string to uppercase:
<%=new String("Hello World").toUpperCase()%>
<br />
<br />
Port of Server :
<%= request.getLocalPort() %>
<br />
<br />
Context path :
<%= application.getContextPath() %>
<br />
<br />
25 multiplied by 4 equals
<%=25 * 4%>
<br />
<br /> Is 75 less than 69?
<%=75 < 69%>
</body>
</html>
Let's invoke this JSP page from a Web browser. You see the table on a browser:
Real-time Examples
In real-time projects, we use JSP expression tags to get values from implicit objects. For example:
<%=request.getAttribute("projectName")%>
<%= application.getAttribute("MyName") %>
We also use the JSP expression tag to display the value of Strings or Objects. For example, consider we have a Task class with id and name as fields:
public class Task {
private int id;
private String name;
// getter and setters
Now, we can display the value of each field of the Task class:
<%= task.getName() %>
<%= task.getId() %>
In the next article, we will learn JSP scriptlet tag with examples.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
🆕 High-Demand
80–90% OFF
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
🆕 High-Demand
80–90% OFF
ChatGPT + Generative AI + Prompt Engineering for Beginners
🚀 Trending Now
80–90% OFF
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
🌟 Top Rated
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
🌟 Top Rated
80–90% OFF
Testing Spring Boot Application with JUnit and Mockito
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Master Spring Data JPA with Hibernate
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
🎓 Student Favorite
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Comments
Post a Comment
Leave Comment