<!-- ex04_member/member.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원 정보</title>
</head>
<body>
<h1>정보 입력</h1>
<form method="get" action="<http://localhost:8080/03_Servlet/memberServlet>">
<table border="1">
<tr>
<td class="title">이 름</td>
<td><input type="text" id="user_name" name="userName" size="20"></td>
</tr>
<tr>
<td class="title">성 별</td>
<td>
<input type="radio" id="gender_m" name="gender" value="남자" checked> 남
<input type="radio" id="gender_f" name="gender" value="여자" > 여
</td>
</tr>
<tr>
<td class="title">취 미</td>
<td>
<input type="checkbox" id="hobby_1" name="hobby" value="독서"> 독서
<input type="checkbox" id="hobby_2" name="hobby" value="영화"> 영화
<input type="checkbox" id="hobby_3" name="hobby" value="음악"> 음악
<input type="checkbox" id="hobby_4" name="hobby" value="게임"> 게임
</td>
</tr>
<tr>
<td class="title">과 목</td>
<td>
<select id="subject" name="subject" size="5" multiple>
<option value="java"> JAVA </option>
<option value="jsp"> JSP </option>
<option value="spring"> Spring </option>
<option value="jquery"> jQuery</option>
<option value="servlet"> Servlet </option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="완료"> <input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
package ex04;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MemberServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String name = request.getParameter("userName");
String gender = request.getParameter("gender");
// parameter가 여러개 일 때 : getParameterValues
String[] hobby_arr = request.getParameterValues("hobby");
String[] subject_arr = request.getParameterValues("subject");
String hobby = "";
if(hobby_arr != null) {
for(int i=0; i<hobby_arr.length;i++) {
if(hobby_arr[i] != null) {
hobby += hobby_arr[i] + ' ';
}
}
}
String subject = "";
if(subject_arr != null) {
for(int i=0; i<subject_arr.length;i++) {
if(subject_arr[i] != null) {
subject += subject_arr[i] + ' ';
}
}
}
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title> 입력 내용 </title>");
out.println("<style>");
out.println("li { color : gray; font-size: 24px; font-weight : bold; }");
out.println("</style>");
out.println("</head>");
out.println("<body>");
out.println("<h2> 입력 내용 </h2>");
out.println("<ul>");
out.println("<li>" + name + "</li>");
out.println("<li>" + gender + "</li>");
out.println("<li>" + hobby + "</li>");
out.println("<li>" + subject + "</li>");
out.println("</ul>");
out.println("<br/></br>");
out.println("<a href='javascript:history.back()'> 이전 페이지 </a>");
out.println("</body>");
out.println("</html>");
}
}