>_
dev-notes

Korean enterprise stack

HOME/MODULES/jsp-jstl

JSP & JSTL

MARCH 2026
8 MIN READ
VERIFIED

?? JSP and JSTL Notes

?? Purpose

JSP renders HTML on the server, and JSTL keeps templates clean by replacing scriptlets with tags.

?? Page Setup

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>

?? Core JSTL Tags (`c:`)

Output (``)

<c:out value="${user.username}"/>

Conditional (``)

<c:if test="${user.status == 'ACTIVE'}">
  <span class="badge-active">Active</span>
</c:if>

Branching (``)

<c:choose>
  <c:when test="${user.status == 'ACTIVE'}">Active</c:when>
  <c:when test="${user.status == 'INACTIVE'}">Inactive</c:when>
  <c:otherwise>Unknown</c:otherwise>
</c:choose>

Loop (``)

<c:forEach var="user" items="${users}" varStatus="s">
  <tr>
    <td>${s.count}</td>
    <td><c:out value="${user.username}"/></td>
    <td><c:out value="${user.email}"/></td>
  </tr>
</c:forEach>

URL (``) and Redirect (``)

<a href="<c:url value='/users/${user.id}'/>">View</a>
<c:redirect url="/login"/>

?? Expression Language (EL)

${user.username}
${empty users}
${not empty users}
${user.status == 'ACTIVE' ? 'Yes' : 'No'}

?? Formatting (`fmt:`)

<fmt:formatDate value="${user.createdAt}" pattern="yyyy-MM-dd HH:mm"/>
<fmt:formatNumber value="${amount}" pattern="#,###"/>

?? Controller to JSP Data Flow

@Controller
public class ViewController {

  @GetMapping("/user-list")
  public String userList(Model model) {
    List<UserResponse> users = userService.getAll();
    model.addAttribute("users", users);
    model.addAttribute("total", users.size());
    return "user-list";
  }
}
<p>Total users: ${total}</p>
<c:forEach var="user" items="${users}">
  <p><c:out value="${user.username}"/></p>
</c:forEach>

?? Common Mistakes

Mistake Better approach
Printing user input with raw ${...} Use <c:out> for escaping
Missing taglib directives Declare required JSTL tags at top
Wrong charset Always use UTF-8 in page directive
Too much logic in JSP Keep business logic in service/controller

? Quick Practice Rules

  • Prefer JSTL + EL over Java scriptlets.
  • Keep JSP focused on display only.
  • Escape user-generated content with <c:out>.
  • Keep date/number format consistent with fmt tags.
Ask This Note

Question-first study help from your note content.

AI Tips

Get practical tips and real-world advice for this topic from OpenAI.

BACK TO OVERVIEW
END OF MODULE LOADED