<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Cute+Font&family=Diphylleia&family=Dokdo&family=Nanum+Brush+Script&family=Nanum+Gothic+Coding&family=Noto+Sans+KR&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<title>Insert title here</title>
</head>
<body>
<div style="margin-left: 200px;">
<form action="ex01_oneAction.jsp" method="post">
<table class="table table-bordered" style="width: 500px;">
<tr>
<th class="table-warning">이름</th>
<td>
<input type="text" class="form-control" name="irum"
style="width: 150px;">
</td>
</tr>
<tr>
<th class="table-warning">생년월일</th>
<td>
<input type="date" class="form-control" name="birth"
style="width: 250px;">
</td>
</tr>
<tr>
<th class="table-warning">취미</th>
<td>
<label><input type="checkbox" name="hobby" value="게임">게임</label>
<label><input type="checkbox" name="hobby" value="운동">운동</label>
<label><input type="checkbox" name="hobby" value="넷플릭스">넷플릭스</label>
<label><input type="checkbox" name="hobby" value="유튜브">유튜브</label>
<label><input type="checkbox" name="hobby" value="코딩">코딩</label>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="submit" class="btn btn-danger">서버전송</button>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
action
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Cute+Font&family=Diphylleia&family=Dokdo&family=Nanum+Brush+Script&family=Nanum+Gothic+Coding&family=Noto+Sans+KR&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<title>Insert title here</title>
</head>
<body>
<%
String name=request.getParameter("irum");
String birth=request.getParameter("birth");
//select가 multiple인 경우는
//getParameterValues로 읽는다(반환타입이 String [])
//이때 선택하지 않으면 null이 되고 선택하면 배열로 값이 넘어온다
String hobby[]=request.getParameterValues("hobby");
%>
<h3 class="alert alert-info">폼태그로부터 읽은 값</h3>
이름:
<%=name %><br>
생년월일:
<%=birth %><br>
취미:
<%
if(hobby==null)
{%>
<b>취미 없음</b>
<%}
else
{
for(int i=0;i<hobby.length;i++)
{%>
[<%=hobby[i] %>]
<%}
}
%>
</body>
</html>