[JSP/Servlet] 설문조사 폼 만들기 예제

researchForm.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>

<h2>설문 조사</h2>

<form action="research.jsp" method="post">

<table>

<tr>

<td>이름 : </td>

<td>

<input type="text" name="name" size="20">

</td>

</tr>

<tr>

<td> 성별 : </td>

<td>

<input type="radio" name="gender" value="male" checked="checked"> 남자

<input type="radio" name="gender" value="female"> 여자

</td>

</tr>

<tr>

<td> 좋아하는 계정 : </td>

<td> 

<input type="checkbox" name="season" value="1"> 봄

<input type="checkbox" name="season" value="2" checked="checked"> 여름

<input type="checkbox" name="season" value="3"> 가을

<input type="checkbox" name="season" value="4"> 겨울

</td>

</tr>

<tr>

<tr align="center">

<td><input type="submit" value="전송"></td>

<td><input type="reset" value="취소"></td>

</tr>

</table>

</form> 

</body>

</html>


research.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>설문 조사 결과</title>

<style type="text/css">

b{

font-size:16pt;

}

</style>

</head>

<body>

<h2>설문 조사 결과</h2>

<%

request.setCharacterEncoding("UTF-8");

String name = request.getParameter("name");

out.println("이름 : <b>"+name+"</b><br>");

String gender = request.getParameter("gender");

out.println("성별 :");

if(gender.equals("male")){

out.println("<b>남자</b><br>");

}else{

out.println("<b>여자</b><br>");

}

String seasonArr[] = request.getParameterValues("season");

out.println("당신이 좋아하는 계절은");

for(String season : seasonArr){

int n = Integer.parseInt(season);

switch(n){

case 1 : out.println("<b> 봄</b>입니다.");

break;

case 2 : out.println("<b> 여름</b>입니다.");

break;

case 3 : out.println("<b> 가을</b>입니다.");

break;

case 4 : out.println("<b> 겨울</b>입니다.");

break;

}

}

%>

<br>

<b><a href='javascript:history.go(-1)'>다시</a></b>

</body>

</html>


결과



댓글

Designed by JB FACTORY