Send06.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send06.jsp</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div>
<h1>JSP를 이용한 데이터 송수신 실습</h1>
<hr>
</div>
<div>
<h2>Send06.jsp ● -> Receive06.jsp ○</h2>
</div>
<div>
<form action="Receive06.jsp" method="post">
이름
<input type="text" name="name">
성별
<input type="radio" name="gender" value="M"> 남자
<input type="radio" name="gender" value="F"> 여자
<br><br>
전공
<select name="major">
<option value="국문">국문학</option>
<option value="영문">영문학</option>
<option value="컴공">컴퓨터공학</option>
<option value="수학">수학</option>
<option value="신방">신문방송학</option>
</select>
<br><br>
<select size="6" multiple="multiple" name="hobby">
<option value="영화">영화감상</option>
<option value="노래">노래감상</option>
<option value="배드민턴">배드민턴</option>
<option value="블로그">블로그 포스팅</option>
<option value="책">책읽기</option>
<option value="우표">우표수집</option>
</select>
<br><br>
<input type="submit" value="내용 전송" class="btn">
</form>
</div>
</body>
</html>
Receive06.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name"); //--텍스트 박스... 단일값 수신
String gender = request.getParameter("gender"); //--라디오 버튼... 단일값 수신
String major = request.getParameter("major"); //--선택 박스... 단일값 수신
String[] hobby = request.getParameterValues("hobby");
//-- 다중 선택이 가능한 select 일 경우... 배열 형태로 수신
String hobbyStr = "";
if(hobby != null)
{
for(String temp : hobby)
{
hobbyStr += "[" + temp + "]";
}
}
String genderStr = "";
if(gender.equals("M"))
{
genderStr ="남자";
}
else if(gender.equals("F"))
{
genderStr="여자";
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Receive06.jsp</title>
</head>
<body>
<div>
<h1>JSP를 이용한 데이터 송수신 실습</h1>
<hr>
</div>
<div>
<h2>Send06.jsp ○ -> Receive06.jsp ●</h2>
</div>
<div>
<h2>수신한 데이터</h2>
<h3>이름 : <%=name %></h3>
<h3>성별 : <%=gender %>(<%=genderStr %>)</h3>
<h3>전공 : <%=major %></h3>
<h3>취미 : <%=hobbyStr %></h3>
</div>
</body>
</html>