if문을 core Tag로 표현해보자!
예제)
<%@page import="java.util.ArrayList"%>
<%@page import="com.luv2code.jsp.tagdemo.Student"%>
<%@page import="java.util.List"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
List<Student> data = new ArrayList<>();
data.add(new Student("mohamad", "sala", false));
data.add(new Student("sadio", "mane", false));
data.add(new Student("diogo", "jose", true));
pageContext.setAttribute("myStudents", data);
%>
<html>
<body>
<table border = "1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Gold Customer</th>
</tr>
<c:forEach var = "tempStudent" items = "${myStudents }">
<tr>
<td>${tempStudent.firstName }</td>
<td>${tempStudent.lastName }</td>
<td>
<c:if test = "${tempStudent.goldCustomer }">
Special Discount
</c:if>
<c:if test = "${not tempStudent.goldCustomer }">
-
</c:if>
</td>
</tr>
</c:forEach>
</body>
</html>
<c:if test = "${tempStudent.goldCustomer}">
</c:if>
VIP 고객(Gold Customer) true값이 넘어오면
Special Discount
- 여기서 문제 보통 if else를 사용였다.
여기서는 else가 없기 때문에 <c:if test = "${not tempStudent.goldCustomer}">을 아래에 붙여야 if else문을 표현할 수 있다.
즉, false 값이 넘어오면
"-" 이 출력이 된다.
이런 표가 만들어 진다.
'Udemy' 카테고리의 다른 글
JSTL Functions Tag (0) | 2021.08.07 |
---|---|
JSTL Core Tag -<choose> (0) | 2021.08.07 |
JSTL Core Tag (Looping with forEach) (0) | 2021.08.07 |
JSTL Core Tag-<forEach> 반복문 (0) | 2021.08.07 |
JSTL 다운로드, 사용법 (0) | 2021.08.06 |