2013년 7월 10일 수요일

(130710) 13일차 FormData.jsp, RequestTest.jsp (request 객체 테스트 - 테이블을 사용해서 회원정보 출력)

 - FormData.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> 회원 가입 </title>
</head>
<body>
<h2> 회원 가입 </h2>
<!-- post는 url에서 숨겨서 보내고, get은 url에 표기해서 보냄 -->
<form action = "RequestTest.jsp" method = "post"> 
  
  아이디 : <input type = "text" name = "id" size = "50"> <br><br>
  패스워드 : <input type = "password" name = "pass"> <br><br>
  당신의 성별은 : <input type = "radio" name = "gender" value = "남성" > 남성
      <input type = "radio" name = "gender" value = "여성"> 여성  <br><br>
  당신의 취미는 : <input type = "checkbox" name = "hobby" value = "음악감상" checked = "checked"> 음악감상
      <input type = "checkbox" name = "hobby" value = "영화감상"> 영화감상
      <input type = "checkbox" name = "hobby" value = "악기연주"> 악기연주  <br><br>
  당신의 직업은 : <select name="job">
      <option value = "학생"> 학생 </option>
      <option value = "개발자"> 개발자 </option>
<option value = "백수"> 백수 </option>
      <option value = "의사"> 의사 </option>
      <option value = "검사"> 검사 </option>
  </select> <br><br>
  하고 싶은말 : <textarea name="talk" rows="5" cols="50"></textarea> <br><br>
<input type="submit" value="전송"> <input type="reset" value="취소">

</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> 회원 정보</title>
</head>
<body bgcolor = lightyellow> <center><h2><b> 가입 결과 </b></h2>

<%
   // 한글처리
  request.setCharacterEncoding("euc-kr");
   // 아이디
  String id = request.getParameter("id");
  // 패스워드
  String pass = request.getParameter("pass");
  // 성별
  String gender = request.getParameter("gender");
  // 취미 (여러개의 값을 받기위해서 배열에 넣음)
  String[] hobby = request.getParameterValues("hobby");
  String temp = "";
  for(int i = 0 ; i < hobby.length ; i++)
    temp = temp + " " + new String(hobby[i].getBytes());
  // 직업
  String job = request.getParameter("job");
  // 하고 싶은말
  String talk = request.getParameter("talk");

out.println("<table border = '2'>");
out.println("<tr>" + "<td>" + "아이디" + "</td>" + "<td>" + id + "</td>" + "</tr>");
out.println("<tr>" + "<td>" + "패스워드" + "</td>" + "<td>" + pass + "</td>" + "</tr>");
out.println("<tr>" + "<td>" + "성별" + "</td>" + "<td>" + gender + "</td>" + "</tr>");
out.println("<tr>" + "<td>" + "취미" + "</td>" + "<td>" + temp + "</td>" + "</tr>");
out.println("<tr>" + "<td>" + "직업" + "</td>" + "<td>" + job + "</td>" + "</tr>");
out.println("<tr>" + "<td>" + "하고 싶은말" + "</td>" + "<td>" + talk + "</td>" + "</tr>" + "</table>");
out.println("<form action = 'FormData.jsp' method = 'post'>" + "<input type='submit' value='이전'>" + "</form>");
  %>
 
</center>
</body>
</html>


 - 결과