자바빈(JavaBean)을 이용한 회원가입 만들기
1. joinMember.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%request.setCharacterEncoding("UTF-8"); %> <!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> <center> <form action="outPut.jsp " method="post"> <table border="1" align="center" bgcolor="YELLOW"> <tr> <td>아이디 : </td> <td><input type="text" name = "id"> </td> </tr> <tr> <td>비밀번호 : </td> <td><input type="password" name="password"> </td> </tr> <tr> <td>이름 : </td> <td><input type="text" name="name"> </td> </tr> <tr> <td>성별 : </td> <td> <input type="radio" name="sex" value="남"> 남 <input type="radio" name="sex" value="여"> 여 </td> </tr> <tr> <td>나이 : </td> <td><input type="text" name="age"> </td> </tr> <tr> <td>이메일주소 : </td> <td><input type="text" name="email"> </td> </tr> <tr> <td>취미 : </td> <td> <input type="checkbox" name="hobby" value="영화">영화 <input type="checkbox" name="hobby" value="축구">축구 <input type="checkbox" name="hobby" value="수영">수영 </td> </tr> </table> <input type="submit" value="전송"> </form> </center> </body> </html> | cs |
2. joinTest.java
10. hobby는 체크박스 : 배열로 받아야 한다.
get/set은 자신의 손을 믿지말고, 자동완성으로 하자
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package join; public class joinTest { private String id; private String password; private String name; private String sex; private String age; private String email; private String hobby[]; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String[] getHobby() { return hobby; } public void setHobby(String[] hobby) { this.hobby = hobby; } } | cs |
3. outPut.jsp
45 : for-each문으로 체크 받은 만큼 출력
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%request.setCharacterEncoding("UTF-8"); %> <jsp:useBean id="joinmember" class="join.joinTest" scope="page"/> <!-- 레퍼런스 명 클래스 명 --> <jsp:setProperty property="*" name="joinmember" /> <!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>Insert title here</title> </head> <body> <table border="1" align="center" bgcolor="YELLOW"> <tr> <td>아이디 : </td> <td><jsp:getProperty name="joinmember" property="id"/></td> </tr> <tr> <td>비밀번호 : </td> <td><jsp:getProperty name="joinmember" property="password"/></td> </tr> <tr> <td>이름 : </td> <td><jsp:getProperty name="joinmember" property="name"/></td> </tr> <tr> <td>성별 : </td> <td><jsp:getProperty name="joinmember" property="sex"/></td> </tr> <tr> <td>나이 : </td> <td><jsp:getProperty name="joinmember" property="age"/></td> </tr> <tr> <td>이메일 주소 : </td> <td><jsp:getProperty name="joinmember" property="email"/></td> </tr> <tr> <td>취미 : </td> <td> <% String[] checkbox = joinmember.getHobby(); for(String i : checkbox){ out.print(i); } %> </td> </tr> </table> </body> </html> | cs |
'Web Programming > JSP' 카테고리의 다른 글
[JSP] JDBC (5) | 2018.05.01 |
---|---|
[JSP] DAO DTO (1) | 2018.05.01 |
[JSP] 한글 처리 (1) | 2018.04.15 |
[JSP] Error Page 이동 (0) | 2018.04.14 |
[JSP] 장바구니 만들기 (0) | 2018.04.13 |