programming/jsp

JSTL - 기초편 3

히연쓰 2021. 5. 13. 16:04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
    tr.first {
        background:#000;
        color:#fff;
    }
    tr.last {
        background:#FFD73C;
        color:#fff;
    }
</style>
</head>
<body>
    <%
        String[] movieList = {"타이타닉""엔드게임","스파이더맨"};    
        pageContext.setAttribute("movieList02", movieList);
    %>
    <table style="width: 500px; text-align: center" border="1">
 
        <thead>
            <tr>
                <th>NO</th>
                <th>COUNT</th>
                <th>TITLE</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach var="movie" items="${movieList02}" varStatus="status">
                <!-- var의 내용 찍어주기 -->
                <c:choose>
                    <c:when test="${status.first }">
                        <tr class="first">
                            <td>${status.count }</td>
                            <td>movie_${status.index }</td>
                            <td>${movie }</td>
                        </tr>
                    </c:when>
                    <c:when test="${status.last }">
                        <tr class="last">
                            <td>${status.count }</td>
                            <td>movie_${status.index }</td>
                            <td>${movie }</td>
                        </tr>
                    </c:when>
                    <c:otherwise>
                        <tr>
                            <td>${status.count }</td>
                            <td>movie_${status.index }</td>
                            <td>${movie }</td>
                        </tr>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
        </tbody>
    </table>
    <ul>
        <c:forEach var="i" begin="1" end="10" step="1" varStatus="status">
            <li>i= ${i} ======= ${status.count }</li>
            <!-- 몇 번 반복했는지 알 수 있음 -->
        </c:forEach>
        <c:forEach var="i" begin="1" end="9" step="1" varStatus="status">
            <li>3 x ${i} ======= ${3*i }</li>
            <!-- 몇 번 반복했는지 알 수 있음 -->
        </c:forEach>
    </ul>
</body>
</html>
cs

결과값
형광펜으로 표시한 부분이 같아야한다.

 

'programming > jsp' 카테고리의 다른 글

JSTL - 구구단 출력  (0) 2021.05.13
JSTL - 기초편4  (0) 2021.05.13
JSTL - 기초편2  (0) 2021.05.13
JSTL - 기초편1  (0) 2021.05.13
jsp - BEAN 작성 쉽게하기  (0) 2021.05.12