-
custom_choose_개념EL, JSTL 2022. 5. 27. 22:47
<form action="Choose.jsp"> <h3>경품 뽑기</h3> 숫자를 입력하세요 : <input type ="number" name="num"><br> <button>확인</button> </form>
Choose.jsp
<%@ page language="java" contentType="text/html; charset="UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <c:choose> <c:when test="${Integer.parseInt(param.num) % 5 == 0}"> 인형을 뽑았습니다. </c:when> <c:when test="${Integer.parseInt(param.num) % 5 == 1}"> 가방을 뽑았습니다. </c:when> <c:when test="${Integer.parseInt(param.num) % 5 == 2}"> 지갑을 뽑았습니다. </c:when> <c:otherwise> 꽝! </c:otherwise> </c:choose> </body> </html>
<c:choose>
: swich문 같은 역할
<c:when>
: case의 역할
<c:otherwise>
: defalut값
choose -> when -> otherwise 기본구조
<c:choose> <c:when test:"경우1"> 경우1이 맞을 경우 실행될 문장 </c:when> <c:when test:"경우2"> 경우2가 맞을 경우 실행될 문장 </c:when> <c:otherwise> 2개의 경우가 아니면 디폴트값이 들어갈 공간 </c:otherwise> </c:choose>
'EL, JSTL' 카테고리의 다른 글
custom_forTokens_개념 (0) 2022.05.27 custom_forEach_개념 (0) 2022.05.27 custom_if_개념 (0) 2022.05.27 custom_multiply_실습문제 (0) 2022.05.27 elOperator (0) 2022.05.27