JAVA

JSTL 사용법/ MAVEN

Strickland 2024. 5. 5. 11:27

pom.xml  에 다음의 의존성 추가

<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>6.0.0</version>
</dependency>
<dependency>
    <groupId>jakarta.servlet.jsp</groupId>
    <artifactId>jakarta.servlet.jsp-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>jakarta.el</groupId>
    <artifactId>jakarta.el-api</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>jakarta.servlet.jsp.jstl</groupId>
    <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jakarta.servlet.jsp.jstl</artifactId>
    <version>3.0.1</version>
</dependency>

 

 

listTodos.jsp 를 다음과 같이 작성

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<html>
<head>
    <title>List Todos Page</title>
</head>
<body>
    <div>Welcome to your page</div>
    <hr>
    <div>your name is ${name}</div>
    <h1>Your Todos are</h1>
    <table>
        <thead>
            <tr>
                <th>id</th>
                <th>Description</th>
                <th>Target Date</th>
                <th>Is Done?</th>
            </tr>

        </thead>
        <tbody>
            <c:forEach items="${todos}" var="todo">
                <tr>
                    <td>${todo.id}</td>
                    <td>${todo.description}</td>
                    <td>${todo.targetDate}</td>
                    <td>${todo.done}</td>
                </tr>

            </c:forEach>
        </tbody>

    </table>

</body>
</html>

 prefix=c 로 설정해 줌으로써 <c:> 를 이용해 JSTL 사용이 가능하다.

'JAVA' 카테고리의 다른 글

커맨드 객체사용/Validation/tag/ MAVEN  (0) 2024.05.08
webjars 를 이용한 bootstrap, jquery 추가 방법 / MAVEN  (0) 2024.05.06
@SessionAttributes  (0) 2024.05.05
JSP 서빙/ MAVEN  (0) 2024.05.04
JDBC / Maven  (0) 2024.05.04