룽쓰의 개발도구

#JSTL의 if와 switch 사용법 본문

CODE_ZIP/JSTL

#JSTL의 if와 switch 사용법

디벨로퍼룽쓰 2021. 4. 20. 17:07

[ A. IF를 사용해보자 ]

<%@ 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>Insert title here</title>
</head>
<body>
<c:if test="${param.num1-param.num2 >= 0 }">
	${param.num1 }<br>
</c:if>
<c:if test="${param.num1-param.num2 < 0 }">
	${param.num2 }<br>
</c:if>
</body>
</html>

 

 

[ B. SWITCH를 사용해보자 ]

<%@ 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>Insert title here</title>
</head>
<body>
<c:choose>
	<c:when test="${param.num==0 }">
		처음 뵙겠습니다.<br>
	</c:when>
	<c:when test="${param.num==1 }">
		반갑습니다.<br>
	</c:when>
	<c:when test="${param.num==2 }">
		어서오세요.<br>
	</c:when>
	<c:otherwise>
		안녕하세요.<br>
	</c:otherwise>
</c:choose>
</body>
</html>