JSP 1일차 request action

form.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Introduce GUI</title>
</head>
<body>

<form action="RequestTest.jsp" method="post">
<table cellpadding="5">
<tr>
<th>ID</th>
<th><input type="text" name="id" size="16"></th>
</tr>
<tr>
<th>P/W</th>
<th><input type="password" name="password" size="16"></th>
<th>Name</th>
<th><input type="text" name="name" size="16"></th>
</tr>
<tr>
<th>Gender</th>
<th><input type="radio" name="gender" value="male"> male
<input type="radio" name="gender" value="female"> female</th>
<th>Hobby</th>
<th><input type="checkbox" name="hobby" value="baseball">baseball
<input type="checkbox" name="hobby" value="soccer">soccer</th>
</tr>
<tr>
<th>Phone</th>
<th colspan="3">
<select name="first_phone">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="019">019</option>
</select>-
<input type="text" name="middle_phone" size="8">-
<input type="text" name="last_phone" size="8"></th>
<tr>
<th>etc</th>
<th colspan="3"><textarea name="etc" rows="3" cols="50"></textarea></th>
<tr>
<th colspan="4">
<center>
<input type="submit" value="Send">
<input type="submit" value="Cancel">
</center>
</th>
</tr>
</table>
</form>

</body>
</html>

requestTest.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Request Test</title>
</head>
<body>

<%
request.setCharacterEncoding("euc-kr");

String id = request.getParameter("id");
String password = request.getParameter("password");
String name = request.getParameter("name");
String gender = request.getParameter("gender");

String[] hobby = request.getParameterValues("hobby");
String hobbies = "";
for(int i=0; i<hobby.length; i++)
  hobbies += hobby[i] + " ";

String phone = request.getParameter("first_phone")
+ request.getParameter("middle_phone")
+ request.getParameter("last_phone");
String etc = request.getParameter("etc");

out.print("ID    : "+id+"<br>");
out.print("P/W   : "+password+"<br>");
out.print("Name  : "+name+"<br>");
out.print("gender: "+gender+"<br>");
out.print("hobby : "+hobbies+"<br>");
out.print("phone : "+phone+"<br>");
out.print("etd   : "+etc+"<br>");
%>

</body>
</html>


result)



댓글 없음: