1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<%@ 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>
</head>
<body>
<c:if test="${param.color==1}">
<h1 style="color: #f00">빨강</h1>
</c:if>
<c:if test="${param.color==2}">
<h1 style="color: #3399cc">모르는 색</h1>
</c:if>
<c:if test="${param.color==3}">
<h1 style="color: #99cc00">모르는 색</h1>
</c:if>
<!-- JSTL에는 else구문 없음 -->
</body>
</html>
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="JSTL_if.jsp">
<select name="color">
<option value="1">빨간</option>
<option value="2">모르는 색</option>
<option value="3">모르는 색 2</option>
</select> <input type="submit" value="색깔 고르기">
</form>
</form>
</body>
</html>
|
cs |
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
|
<%@ 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>
</head>
<body>
<!-- choose에는 otherwise기능이 있다. -->
<!-- switch case랑 유사 -->
<c:choose>
<c:when test="${param.fruit ==1 }">
<h1>사과</h1>
</c:when>
<c:when test="${param.fruit ==2 }">
<h1>참외</h1>
</c:when>
<c:when test="${param.fruit ==3 }">
<h1>수박</h1>
</c:when>
<c:otherwise>
<h1>선택된 과일이 없습니다</h1>
</c:otherwise>
</c:choose>
</body>
</html>
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="fruit_select.jsp">
<select name="fruit">
<option value="">과일을 고르세요</option>
<option value="1">사과</option>
<option value="2">참외</option>
<option value="3">수박</option>
</select> <input type="submit" value="과일 고르기">
</form>
</body>
</html>
|
cs |
참외 라는 결과값이 나온다.
'programming > jsp' 카테고리의 다른 글
JSTL - 기초편4 (0) | 2021.05.13 |
---|---|
JSTL - 기초편 3 (0) | 2021.05.13 |
JSTL - 기초편1 (0) | 2021.05.13 |
jsp - BEAN 작성 쉽게하기 (0) | 2021.05.12 |
jsp - summernote 이용하기2 (0) | 2021.05.11 |