Category: java
Jstl and expression language
Published on 30 Sep 2026
Explanation
JSTL provides standard tags for common JSP operations such as conditions, loops, formatting, and URL handling.
Code:
<%@ taglib prefix="c"
uri="jakarta.tags.core" %>
<c:if test="${user != null}">
Welcome!
</c:if>
Explanation
Expression Language allows JSP pages to access Java objects and values without writing Java scriptlets.
Code:
${user.name}
${user.email}
${sessionScope.username}
Explanation
Use c:forEach to iterate through a collection in a JSP page.
Code:
<c:forEach var="user" items="${users}">
<p>${user.name}</p>
</c:forEach>
Explanation
Use JSTL conditional tags instead of Java if statements directly inside JSP pages.
Code:
<c:choose>
<c:when test="${user.admin}">
Admin
</c:when>
<c:otherwise>
User
</c:otherwise>
</c:choose>
Explanation
EL supports property access, arithmetic, logical operators, and conditional expressions.
Code:
${user.age >= 18}
${user.name}
${price * quantity}
${empty users}