1. 우선 데이터 전송객체인 BoardVo 클래스 생성
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package jspstudy.domain;
public class BoardVo {
private int bidx;
private int originbidx;
private int depth;
private int level_;
private String subject;
private String content;
private String writer;
private String writeday;
private String delyn;
private String ip;
private int midx;
private String filename;
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public int getMidx() {
return midx;
}
public void setMidx(int midx) {
this.midx = midx;
}
public int getBidx() {
return bidx;
}
public void setBidx(int bidx) {
this.bidx = bidx;
}
public int getOriginbidx() {
return originbidx;
}
public void setOriginbidx(int originbidx) {
this.originbidx = originbidx;
}
public int getDepth() {
return depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
public int getLevel_() {
return level_;
}
public void setLevel_(int level_) {
this.level_ = level_;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getWriteday() {
return writeday;
}
public void setWriteday(String writeday) {
this.writeday = writeday;
}
public String getDelyn() {
return delyn;
}
public void setDelyn(String delyn) {
this.delyn = delyn;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
}
|
cs |
2. JSP 페이지 구현
<body부분>
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
60
61
62
63
64
65
66
67
68
|
<form name="frm">
<table border="1" style="text-align:left;width:800px;height:300px">
<tr>
<td>아이디</td>
<td><input type="text" name="memberId" size="30"></td>
</tr>
<tr>
<td>비밀번호</td>
<td><input type="password" name="memberPwd" size="30"></td>
</tr>
<tr>
<td>비밀번호 확인</td>
<td><input type="password" name="memberPwd2" size="30"></td>
</tr>
<tr>
<td>이름</td>
<td><input type="text" name="memberName" size="30"></td>
</tr>
<tr>
<td>이메일</td>
<td><input type="email" name="memberEmail" size="30"></td>
</tr>
<tr>
<td>성별</td>
<td>
<input type="radio" name ="memberGender" value="M" checked>남
<input type="radio" name ="memberGender" value="F">여
</td>
</tr>
<tr>
<td>지역</td>
<td><select name="memberAddr" style="width:100px;height:25px">
<option value="전주">전주</option>
<option value="대전">대전</option>
<option value="서울">서울</option>
</select>
</td>
</tr>
<tr>
<td>연락처</td>
<td>
<input type="text" name="memberPhone" size="30">
</td>
</tr>
<tr>
<td>주민번호</td>
<td><input type="number" name="memberJumin" size="30">
</td>
</tr>
<tr>
<td>취미</td>
<td>
<input type="checkbox" name ="memberHobby" value="축구" checked>축구
<input type="checkbox" name ="memberHobby" value="농구">농구
<input type="checkbox" name ="memberHobby" value="야구">야구
</td>
</tr>
<tr>
<td>확인</td>
<td>
<input type="button" value="확인" onclick="check();">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
|
cs |
<script> 부분
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
60
|
function check(){
var fm = document.frm;
if (fm.memberId.value==""){
alert("아이디를 입력해주세요");
fm.memberId.focus();
return;
}else if (fm.memberPwd.value==""){
alert("비밀번호를 입력해주세요");
fm.memberPwd.focus();
return;
}else if (fm.memberPwd2.value==""){
alert("비밀번호 확인을 입력해주세요");
fm.memberPwd2.focus();
return;
}else if (fm.memberPwd.value != fm.memberPwd2.value){
alert("비밀번호가 일치하지 않습니다.");
fm.memberPwd2.value = "";
fm.memberPwd2.focus();
return;
}else if (fm.memberName.value==""){
alert("이름을 입력해주세요");
fm.memberName.focus();
return;
}else if (fm.memberEmail.value==""){
alert("이메일을 입력해주세요");
fm.memberEmail.focus();
return;
}else if (fm.memberPhone.value==""){
alert("연락처를 입력해주세요");
fm.memberPhone.focus();
return;
}else if (fm.memberJumin.value==""){
alert("주민번호를 입력해주세요");
fm.memberJumin.focus();
return;
}else {
var flag = false;
for(var i=0;i<fm.memberHobby.length;i++){
if(fm.memberHobby[i].checked ==true){
flag = true;
break;
}
}
if (flag == false){
alert("한개이상 선택해주세요");
return;
}
}
alert("전송합니다..");
//fm.action = "./memberJoinOk.jsp";
//가상경로 사용
fm.action = "<%=request.getContextPath()%>/member/memberJoinAction.do";
fm.method = "post";
fm.submit();
return;
}
|
cs |
3. Controller 구현
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
|
@WebServlet("/MemberController")
public class MemberController extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String uri = request.getRequestURI();
String pj = request.getContextPath();
String command = uri.substring(pj.length());
System.out.println("command:"+command);
if(command.equals("/member/memberJoinAction.do")) {
String memberId = request.getParameter("memberId");
String memberPwd = request.getParameter("memberPwd");
String memberName = request.getParameter("memberName");
String memberEmail = request.getParameter("memberEmail");
String memberPhone = request.getParameter("memberPhone");
String memberJumin = request.getParameter("memberJumin");
String memberGender = request.getParameter("memberGender");
String memberAddr = request.getParameter("memberAddr");
String[] memberHobby = request.getParameterValues("memberHobby");
String hobby = "";
for(int i=0; i<memberHobby.length;i++){
hobby = hobby +","+ memberHobby[i];
//out.println(memberHobby[i]+"<br>");
}
hobby = hobby.substring(1);
String ip = InetAddress.getLocalHost().getHostAddress();
MemberDao md = new MemberDao();
int value = md.insertMember(memberId,memberPwd,memberName,memberGender,memberAddr,memberJumin,memberPhone,hobby,memberEmail,ip);
// PrintWriter out = response.getWriter();
//입력이 되었으면
if (value ==1){
response.sendRedirect(request.getContextPath()+"/member/memberList.do");
// out.println("<script>alert('회원가입성공'); location.href='"+request.getContextPath()+"/'</script>");
}else{
response.sendRedirect(request.getContextPath()+"/member/memberJoin.do");
// out.println("<script>alert('회원가입실패'); location.href='./memberJoin.html'</script>");
}
}else if (command.equals("/member/memberJoin.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/member/memberJoin.jsp");
rd.forward(request, response);
|
cs |
4. Dao구현
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
|
package jspstudy.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import jspstudy.dbconn.Dbconn;
import jspstudy.domain.MemberVo;
public class MemberDao {
private Connection conn;
private PreparedStatement pstmt;
public MemberDao() {
Dbconn db = new Dbconn();
this.conn = db.getConnection();
}
public int insertMember(String memberId,String memberPwd,String memberName,String memberGender,String memberAddr,String memberJumin,String memberPhone,String hobby, String memberEmail,String ip){
int value=0;
String sql = "insert into b_member(MIDX,MEMBERID,MEMEBERPWD,MEMBERNAME,MEMBERGENDER,MEMBERADDR,MEMBERJUMIN,MEMBERPHONE,MEMBERHOBBY,MEMBEREMAIL,MEMBERIP) "
+"values(midx_b_seq.nextval,?,?,?,?,?,?,?,?,?,?)";
// 구문을 실행하고 리턴값으로 실행되었으면 1 아니면 0을 value 변수에 담는다
//연결객체를 통해서 Statement 구문객체를 생성해서 stmt에 담는다
try{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, memberId);
pstmt.setString(2, memberPwd);
pstmt.setString(3, memberName);
pstmt.setString(4, memberGender);
pstmt.setString(5, memberAddr);
pstmt.setString(6, memberJumin);
pstmt.setString(7, memberPhone);
pstmt.setString(8, hobby);
pstmt.setString(9, memberEmail);
pstmt.setString(10,ip);
value = pstmt.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}finally {
try {
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return value;
}
|
cs |
'기존 > 🏀Jsp' 카테고리의 다른 글
[댓글]JSP (0) | 2022.11.02 |
---|---|
[JSP-3편](oracle) 회원가입 구현하기 dao (jsp회원가입) (0) | 2022.07.20 |
[JSP-2편](oracle) web.xml mapping 설정 (0) | 2022.07.20 |
[JSP-2편](mysql) web.xml mapping 설정 (0) | 2022.07.20 |
[JSP-1편](oracle) db 연결 jar 파일 포함 (0) | 2022.07.20 |