메뉴 건너뛰기

2019.01.09 10:30

아이디 체크

조회 수 895 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

1. 회원가입 페이지 아이디 옆에 스펜테그 입력 , 위에 스크립트로 keyup 함수 작성


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE  >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.1.0.js">
    
</script>
 
<script>
    $(document).ready(function() {
        //아이디 중복체크
 
        $("#userid").keyup(function() {
            //사용자가 입력한 아이디
 
            var userid = $("#userid").val();
 
            var param = "userid=" + userid;
 
            if (userid.length >= 4) { //최소 글자수 이상
 
                //아이디 체크
 
                $.ajax({
                    type : "post",
                    url : "/web02/member_servlet/idcheck.do",
                    data : param,
                    success : function(result) {
 
                        $("#span_id").html(result);
 
                    }
 
                })
 
            }
 
        });
        
        
        //버튼클릭 이벤트
        $("#btnJoin").click(function() {
        
            //폼데이터를 서버에 제출
            document.form1.submit();
 
        });
 
    });
</script>
 
</head>
<body>
 
 
    <h2>회원가입</h2>
 
 
    <form name="form1" method="post" action="/web02/member_servlet/join.do">
 
        <table border="1" width="700px">
            <tr>
                <td>이름</td>
                <td><input type="text" name="name" id="name"></td>
            </tr>
 
 
            <tr>
                <td>아이디</td>
                <td><input type="text" name="userid" id="userid"> <span id="span_id"></span></td>
            </tr>
 
 
            <tr>
                <td>비밀번호</td>
                <td><input type="password" name="passwd" id="passwd"></td>
            </tr>
 
 
            <tr>
                <td>비밀번호확인</td>
                <td><input type="password" name="passwd2" id="passwd2"></td>
            </tr>
 
 
            <tr>
                <td>이메일</td>
                <td><input type="email" name="email" id="email"></td>
            </tr>
 
 
            <tr>
                <td>폰번호</td>
                <td><input type="text" name="hp" id="hp"></td>
            </tr>
 
 
            <tr>
                <td>우편번호</td>
                <td><input type="text" name="zipcode" id="zipcode"></td>
            </tr>
 
 
            <tr>
                <td>주소</td>
                <td><input type="text" name="address1" id="address1"></td>
            </tr>
 
 
            <tr>
                <td>주소상세</td>
                <td><input type="text" name="address2" id="address2"></td>
            </tr>
 
 
            <tr>
 
                <td  align="center" colspan="2">
                <input type="button" value="회원가입" id="btnJoin"> 
                <input type="reset" value="취소">
 
                </td>
            </tr>
 
        </table>
    </form>
 
</body>
</html>
cs



2.컨트롤 

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
        //아이디 체크
        } else if (url.indexOf("idcheck.do"!= -1) {
 
            String userid = request.getParameter("userid");
 
            
            System.out.println("userid"+userid);
            
            int idcheck = dao.idcheck(userid);
 
            System.out.println("idcheck"+idcheck);
            
            String message = "";
 
            if (idcheck==0) {
 
                message = userid + "는 사용가능한 아이디 입니다.";
 
            } else {
 
                message = userid + "는 사용할 수 없는 아이디 입니다.";
            }
            request.setAttribute("message", message);
            // 페이지 이동
 
            String page = "/member/idcheck.jsp";
            RequestDispatcher rd = request.getRequestDispatcher(page);
            rd.forward(request, response);
        }
 
    }
cs



3.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
58
59
60
61
62
63
// idcheck
    public int idcheck(String userid) {
 
    
        
        
        Connection conn = null// db접속
        PreparedStatement pstmt = null// sql 실행
        ResultSet rs = null// select 결과 처리
        int result =1;
        try {
 
            conn = DB.dbConn(); // db접속 성공
 
            String sql = "select count(*) from member where userid=?";
 
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, userid);
 
            rs = pstmt.executeQuery(); // rs에 실행결과 리턴
 
            
            if (rs.next()) { // 레코드가 존재하면
 
                    result = rs.getInt(1);
            }
 
        } catch (Exception e) {
 
            e.printStackTrace();
        } finally {
            
            try {
                if (rs != null) {
                    rs.close();
                }
 
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (pstmt != null) {
                    pstmt.close();
                }
 
            } catch (Exception e2) {
                e2.printStackTrace();
            }
 
            try {
                if (conn != null) {
                    conn.close();
                }
 
            } catch (Exception e2) {
                e2.printStackTrace();
            }
 
        }
 
        return result;
 
    }
cs



4. 아이디 사용여부 표시 


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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE  >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 
    <%
        String message = (String) request.getAttribute("message");
 
        if (message.indexOf("사용가능한"!= -1) {
    %>
 
    <span style="color: blue;"><%=message%> </span>
 
    <%
        } else {
    %>
 
    <span style="color: red;"><%=message%></span>
 
    <%
        }
    %>
 
 
</body>
</html>
cs



List of Articles
번호 제목 날짜 조회 수
65 JSP 게시판 만들기 - 구현 (MySQL과의 연동) file 2017.09.12 37895
64 JSP 게시판 만들기 - 구현 (Method, Query 기초) file 2017.09.12 30633
63 MYSQL JSP insert 폼에서 servlet으로 값넘기기 2019.01.09 26165
62 JSP - 로그인 & AJAX 비동기 방식으로 처리&암호화&정규표현식 2021.03.28 19438
61 JSP 게시판 만들기 - 구현 (HTML 코딩) file 2017.09.12 17066
60 JSP 게시판 만들기 - 구현 (이클립스 웹 프로젝트 생성) file 2017.09.12 13393
59 JSP 게시판 만들기 - 구현 (디렉토리, 파일, 테이블 생성) file 2017.09.12 7909
58 JSP (Java Server Page), Servlet에 대해 file 2017.09.12 6709
57 JSP 게시판 만들기 - 개발표준, 화면설계 file 2017.09.12 6596
56 JSP 게시판 만들기 - 구현 (마무리, 테스트) file 2017.09.12 6581
55 CentOS(64Bit)에 yum을 이용하여 Apache+Tomcat+JSP 연동 2018.03.28 5934
54 JSP 게시판 만들기 - 완료 (소스파일, 의견) 2017.09.12 5511
53 JSP 게시판 만들기 - 구현 (웹 프로젝트와 톰켓 연동, 샘플 페이지 작성) file 2017.09.12 5185
52 JSP 게시판 만들기 - 네이밍, 데이터베이스 설계 file 2017.09.12 4981
51 JSP 게시판 만들기 - 구현 (이클립스 웹 프로젝트 생성) file 2017.09.12 4881
50 JSP 게시판 만들기 - 구현 (파라미터, 요청/응답) file 2017.09.12 4799
49 JSP 게시판 만들기 - 시스템 아키텍처 file 2017.09.12 4781
48 MYSQL JSP 연동 &리스트 뽑아오기 2019.01.09 4437
47 Oracle Database DB연결, table 생성 file 2017.09.11 4264
46 스크립틀릿(Scriptlet), 선언(declaration), 표현식(expression) file 2017.09.12 3637
Board Pagination Prev 1 2 3 4 Next
/ 4

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved