잡동사니에도 사랑을

[21.10.07] jstlInput / jstlResult(jstl) 본문

JAVA_EE/EL-JSTL

[21.10.07] jstlInput / jstlResult(jstl)

luvforjunk 2021. 10. 7. 18:23
728x90
반응형

////////jstlInput.jsp

<%@ 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 name="" method="post" action="jstlResult.jsp">
	<table border="1" cellpadding="3" cellspacing="0">
		<tr>
			<td>이름</td>
			<td><input type="text" id="name" name="name"></td>
		</tr>
		
		<tr>
			<td>나이</td>
			<td><input type="text" id="age" name="age"></td>
		</tr>
		
		<tr>
			<td>색깔</td>
			<td>
				<select name="color" style="width: 100px;">
					<optgroup label="색깔">
						<option value="red">빨 강</option>
				        <option value="green">초 록</option>
				        <option value="blue">파 랑</option>
				        <option value="violet">보 라</option>
				        <option value="cyan">하 늘</option>
					</optgroup>
				</select>
			</td>
		</tr>
		
		<tr>
			<td>취미</td>
			<td>
				<fieldset>
					<legend>취미</legend>
					<input type="checkbox" name="hobby" value="독서">독서
					<input type="checkbox" name="hobby" value="영화">영화
					<input type="checkbox" name="hobby" value="음악">음악
					<input type="checkbox" name="hobby" value="게임">게임
					<input type="checkbox" name="hobby" value="쇼핑">쇼핑
				</fieldset>
			</td>
		</tr>
		
		<tr>
			<td colspan="2" align="center">
				<input type="submit" value="SEND">
				<input type="reset" value="CANCEL">
			</td>
		</tr>
	</table>
</form>
</body>
</html>

 

 

 

////////jstlResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<fmt:requestEncoding value="UTF-8" />
<style type="text/css">
body {
	color: ${param.color};
}
</style>
</head>
<body>
<!-- request.setCharacterEncoding("UTF-8") -->
<!-- post방식일 때만 써준다 주소를 타는 get방식일 때는 필요없음 -->
<ul>
	<li>이 름 : ${param.name }
	</li><br>
	
	<li>나 이 : ${param.age }
		<c:if test="조건"></c:if>
	
		<c:if test="${param.age >= 20 }">
			<strong>성인</strong>
		</c:if>
	
		<c:if test="${param.age < 20 }">
			<strong>청소년</strong>
		</c:if>
	<%-- test안에 써주는 건 조건 --%>
	</li><br>
	
	<li>색 깔 : 
		<c:if test="${param.color == 'red' }"><strong>빨강</strong></c:if>
		<c:if test="${param.color == 'green' }"><strong>초록</strong></c:if>
		<c:if test="${param.color == 'blue' }"><strong>파랑</strong></c:if>
		<c:if test="${param.color == 'violet' }"><strong>보라</strong></c:if>
		<c:if test="${param.color == 'cyan' }"><strong>하늘</strong></c:if>
	</li><br>
	
	<li>취미 :
		${ paramValues['hobby'][0]} <!-- paramValues.hobby[0] -->
		${ paramValues['hobby'][1]}
		${ paramValues['hobby'][2]}
		${ paramValues['hobby'][3]}
		${ paramValues['hobby'][4]}
	</li><br>
	
	<li>취미 : <br>
		<c:forEach var="data" items="${paramValues.hobby }" varStatus="i">
            인덱스 = ${i.index } &emsp; 개수 = ${i.count } &emsp; ${data }<br>
         </c:forEach>
	</li><br>
</ul>
</body>
</html>

 

 

결과1 - jstlInput

 

결과2 - jstlResult

 

728x90
반응형