본문 바로가기

Oracle

jsp+db 회원가입, 로그인

로그인.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
<%@ 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>
<form action="loginOk.jsp" name ="login" method="post"<!-- 아이디, 비밀번호정보를 로그인OK로 보내거나 회원가입으로 이동 -->
<table border="1">
    <tr>
    <td>아이디 :</td
    <td><input type="text" name="id" id="id"></td>
    </tr>
    <tr>
    <td>비밀번호 :</td
    <td><input type="text" name="pw" id="pw">></td>
    </tr>
    <tr>
    <td><input type="submit" value="로그인"></td>
    <td><a href="join.jsp">회원가입</a></td>
    </tr>
</table>
</body>
</html>
cs

비밀번호를 표시하고싶지않으면 그냥 input타입을 바꾸면된다.

로그인 검사페이지

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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    <%@ page import = "java.sql.*" %>
    <%@ page import="javax.sql.*"%>
    <%@ page import="javax.naming.*"%>
    <%@page import="java.util.*"%>
    
 <%
    String id = request.getParameter("id");        /* 로그인 페이지에서 아이디, 비밀번호 정보를 받아온다 */
     String pw = request.getParameter("pw");
 
     
     Connection conn = null;/* 디비랑 연결할떄 */
     PreparedStatement stmt = null;/* 디비에 값 넘길때 */
     ResultSet rs = null;/*디비 값 불러올떄  */
     
     try{/*디비와 연결한다.  */
         Context init = new InitialContext();
         DataSource ds = (DataSource)init.lookup("java:comp/env/jdbc/OracleDB");
         conn = ds.getConnection();
         
         
         String sql = "SELECT * FROM INFO WHERE ID=?"/* 쿼리문 */
         stmt = conn.prepareStatement(sql); /*conn으로 연결한뒤 , statement로 값을 넘긴다,쿼리문을 실행한다.  */
         stmt.setString(1,id);/*쿼리문에 1번쨰 ?로 입력 될 값 id가 들어간다.  */
         rs = stmt.executeQuery();/*execute(실행한다)Query를 */
         
         if(rs.next()){ /* ResultSet */
             if(pw.equals(rs.getString("pass"))){ /*내가 친 패스워드랑 테이블에 패스워드 비교 후 같으면 */
                 session.setAttribute("id", id); /*   */
                 
                 out.println("<script>");
                 out.println("location.href='admin.jsp'"); /* admin으로 넘김 */
                 out.println("</script>");
             }
         }
         
         out.println("<script>");
                 out.println("location.href='login.jsp'");/* 다르면 로그인으로 넘김 , 예외처리.*/
                         out.println("</script>");
     }catch(Exception e){
         e.printStackTrace();
     }finally{
         try{/* 전부 닫고 끝 */
             rs.close();
             stmt.close();
             conn.close();
         }catch(Exception e){
             e.printStackTrace();
         }
     }
    
 
    %>
<!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>
 
</body>
</html>
cs

로그인이 바로 됬는지 검사한다.


회원가입

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.util.*"%>
<%
 
    request.setCharacterEncoding("UTF-8");
 
%>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>유효성 검사 회원가입</title>
    <script language="javascript">
        
    function checked()
    {    //id값을 연결한다
        var idtext = document.getElementById("ide");
            //아이디의 id값
            var patext = document.getElementById("pass");
            //비밀번호의 id값
            var cpatext = document.getElementById("cpass");
           //비밀번호확인의 id값
            var mtext = document.getElementById("mail");
           //e-mail의 id값
            var nametext = document.getElementById("name");
           //이름의 id값
            var hobby = document.getElementsByName("hobby");
           //체크박스의 취미 id값
            var intro =  document.getElementById("intro");
 
        var id = idtext.value;//id라는 변수에 아이디 박스에서 쓰여진 값을 대입한다.
        var password = patext.value;//비밀번호 박스에 쓰여진 값을 대입
        var cpassword = cpatext.value;
        var mail = mtext.value;
        var name = nametext.value;
 
 
        var regExp1 = /^[a-zA-Z0-9]{4,12}$/;//유효성 검사 정규식표현법
        //|| /(정규표현식의 시작,끝) ^(문장시작) [](범위) 소문자a-z대문자A-Z숫자0-9를 포함 ,최소 4,최대 12자 까지 허용한다.
        //아이디 비밀번호 유효성 검사
        var regExp2 = /[a-z0-9]{2,}@[a-z0-9-]{2,}\.[a-z0-9]{2,}/i;
        //이메일 유효성검사
        var regname = /^[가-힝]{2,}$/;
        //이름 유효성 검사
 
        if(!regExp1.test(id))
             //아이디 유효성 검사 후 4~12자의 영문 대소문자와 숫자의 유효성이 안 맞다면
             //공백을 주고 알람을 띄운다.
             //밑에 동일한 유효성 검사
            {
                alert("형식에 맞춰 ID를 입력하세요");
                idtext.value = "";
                idtext.focus();
                return false;
            }
        else if(!regExp1.test(password))
        {
            alert("형식에 맞춰 비밀번호를 입력해라");
            patext.value="";
            patext.focus();
            return false;
        }
        else if(!(cpassword.slice(0,cpassword.length=== password.slice(0,password.length)))//slice함수는 배열에쓴다 배열에 담긴 시작,원하는 지점 까지의 문자를 반환한다cpqssword배열의 0번쨰부터 배열 길이만큼에있는 문자열을 반환하겠단 이야기 "==="는 타입까지 비교해서 같으면 트룽를 반환한다. 그러니깐 어느한쪽이 정수고 한쪽이 문자열이면 
            {//비밀번호가 같은지 확인한다. 유효성 검사 통과 못했을때
                alert("비밀번호가 동일하지 않스빈다.");
                cpatext.value = "";
                cpatext.focus();
                return false;
            }
            else if((cpassword.slice(0,cpassword.length=== id.slice(0,id.length)))
            {//비밀번호끼리 비교해서 트루가나오면 일로온다 아이디의 문자열과 비밀번호를 비교한다.    유효성 검사 통과 못했을때
                alert("비밀번호가 ID랑 같은면 안되");
                patext.value="";
                patext.focus();
                cpatext.value="";
                cpatext.focus();
                return false;
                //유효성 검사를 통과못하면 비밀번호,비번확인까지 초기화시킨다. 
            }
            else if(!regExp2.test(mail))
            {
                alert("제대로된 메일이 아닙니다.");
                mtext.value="";
                mtext.focus();
                return false;
            }
            else if(!regname.test(name))
            {
                alert("이름 똑바로 써라");
                nametext.value= "";
                nametext.focus();
                return false;
            }
            //c체크박스 유효성검사
        else if(document.data.hobby[0].checked==false&&
                document.data.hobby[1].checked==false&&
                document.data.hobby[2].checked==false&&
                document.data.hobby[3].checked==false&&
                document.data.hobby[4].checked==false){
                alert("관심분야를 체크해라");
            return false;
            }
                
                //자기소개유효성검사
                else if(intro.value == ""){
                    alert("자기 소개란을 100자 내외로 기입해주세오");
                    return false;
                }
                else
                {
                    if (checks())
                     {
                        alert("회원가입을 진행합니다.");
                        return true;
                    }
                    else
                    {//엘스문안의 엘스문
                        return false;
                    }
                }
 
            }
 
            //주민번호 검사
            function check_jumin() {
                var jumin = document.getElementById('pnum').value +document.getElementById('nnum').value;
                //jumin 변수에 주민번호 앞자리(pnum)+뒷자리(nnum) 를 넣어준다.
                var fmt = /^\d{6}[1234]\d{6}$/;
                //"\d"<<숫자, {6}<<갯수 []<<범위,\d{6}
                //숫자6개,범위 [1234]에 다시 숫자 6개 유효성검사
                //주번 앞 6자리, 뒤 7자리를 뜻한다. "-"표시가 없으니 오류나면 확인할것
                        
                if(!fmt.test(jumin)){//fmt로 jumin을 검사할때 거짓이면
                    //발동
                    return false;
                }
                var birthYear = (jumin.charAt(6<= "2") ? "19" : "20";
                //삼항연산자 주번 뒤의첫번째자리가 2보다 크거나 같으면 
                //즉 참이면 19를 거짓이면 20을 birthYear에 넣는다.
                birthYear += jumin.substr(0,2);//생년
                //substr(int,int)<<지정 인덱스 부터 몇개의 문자를 출력한다. 
                //문자를 자르는 함수이경우 0번부터 2개의 문자열을 가지고온다.
                var birthMonth = jumin.substr(2,2)-1;//월
                var birthDate = jumin.substr(4,2);//일
                var birth = new Date(birthYear,birthMonth,birthDate);
                //생년월일을 각각 자른다음배열에 넣었따.
 
                if(birth.getYear() % 100 != jumin.substr(0,2||
                    birth.getMonth() != birthMonth ||
                    birth.getDate() != birthDate) {
                    return false;
                }
                    /*//DATA.getYear()<<는 지금의 년도를 구한다. 
                    //지금 년도에서 100을 나눈 나머지 값이 주민의 인덱스 0부터 2번째자리 즉 입력한 사람의 년도와 다르면 ?
                    주민번호 유효성검사뒤 생일을 자동으로 입력하는 곳*/
                
 
                var buf = new Array(13);
                for (var i = 0; i <13; i++
                buf[i] = parseInt(jumin.charAt(i));//parseInt<<문자를 정수로 바꿔줌
                //여기서부터 입력받은 주민번호를 정수로 바꾼뒤 유효성 검사를 시작한다.
                multipliers = [234567892345];
                for(var sum = 0, i=0; i<12;i++)
                    sum +=(buf[i] *= multipliers[i]);
                if ((11 - (sum % 11)) % 10 != buf[12]) {
                    return false;
                }
                return true;
            }
                    
                function checks() {
                    if (check_jumin()) {
                        alert("올바른 주민번호");
                        var year1 = document.getElementById("year");
 
                        var num1 = document.getElementById('pnum');
                        var num2 = num1.value;
                        var num3 = num2.substring(0,2);//주민번호에서 생년월일을 스트링으로 뺸다
                        var num4 = num2.substring(3,4);
                        var num5 = num2.substring(4,6);
                  
                        year1.value = "19" + num3;
 
                        document.data.mon.value = num4;
                        document.data.day.value = num5;
                        return true;
 
                    }
                    else
                        var num1 = document.getElementById('pnum');
                        var num2 = document.getElementById('nnum');
                        alert("똑바로써라");
                        num1.value = "";
                        num1.focus();
                        num2.value = "";
 
                        return false;
                }
                //주민번호 유효성 검사 끝
 
    </script>
</head>
<body>
<!-- 폼 -->
<form action="joinOk.jsp"  method="post" name="data" onsubmit= "return checked()">
 
<!-- 테이블 시작-->
    <table name= "data" style="border-collapse:collapse; border:1px gray solid; width ="700" height="230" border="1" align="center">
    <!-- 첫줄  -->    
        <tr>
            <td colspan="2" align = "center" bjcolor="33ffcc" bgcolor="33ffcc">회원 기본 정보</td> 
        </tr>
<!-- 두번째줄 아이디-->
        <tr>
        <td align="center" bgcolor="D5D5D5">아이디</td>
        <td><input type="text" name="ide" id="ide" size=" 20" maxlength="12" />4~12자의 영문 대소문자와 숫자로만 입력 </td>
        </tr>
<!-- 세번쨰 비밀번호 -->
        <tr>
            <td align="center" bgcolor="D5D5D5">비밀번호</td>
            <td><input type="password" id="pass" name="pass" size="20" maxlength="12">4~12자의 영문 대소문자와 숫자로만 입력 </td>
        </tr>
<!-- 네번째 비밀번호 확인 -->
        <tr>
            <td align="center" bgcolor="D5D5D5">비밀번호 확인</td>
            <td><input type="password" name="비밀번호확인" id="cpass" size="20" maxlength="12"></td>
        </tr>
        <!-- 다섯번째 이름  -->
        <tr>
            <td align="center" bgcolor="D5D5D5">메일주소</td>
            <td><input type="text" name="mail" id="mail" size="20" ></td>
        </tr>
        <tr>
            <td align="center" bgcolor="D5D5D5">이름 : </td>
            <td><input type="text" name="name" id="name" size="20"></td>
        </tr> 
        <!-- 여섯번째  -->
        <tr>
            <td colspan="2" align="center" bgcolor="33ffcc">개인신상 정보</td>
        </tr>
        <!-- 주민등록번호 -->
        <tr>
            <td align="center" bgcolor="D5D5D5">주민등록번호</td>
            <td><input type="text" name="pnum" id ="pnum" size="6" maxlength="6"/> - <input type="text" id="nnum" name="my_name" size="7" maxlength="7">예)123456-1234567</td>
        </tr>
        <!-- 생일 -->
        <tr>
            <td align="center" bgcolor="D5D5D5">생일</td>
            <td><input type="text" name="year" size="5" maxlength="4" id="year">년
                <select name="mon" id="mon">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                </select> 월
                <select name="day" id ="day">
                    <option value="1">    1    </option>
                    <option value="2">    2    </option>
                    <option value="3">    3    </option>
                    <option value="4">    4    </option>
                    <option value="5">    5    </option>
                    <option value="6">    6    </option>
                    <option value="7">    7    </option>
                    <option value="8">    8    </option>
                    <option value="9">    9    </option>
                    <option value="10">    10    </option>
                    <option value="11">    11    </option>
                    <option value="12">    12    </option>
                    <option value="13">    13    </option>
                    <option value="14">    14    </option>
                    <option value="15">    15    </option>
                    <option value="16">    16    </option>
                    <option value="17">    17    </option>
                    <option value="18">    18    </option>
                    <option value="19">    19    </option>
                    <option value="20">    20    </option>
                    <option value="21">    21    </option>
                    <option value="22">    23    </option>
                    <option value="22">    24    </option>
                    <option value="22">    25    </option>
                    <option value="22">    26    </option>
                    <option value="22">    27    </option> 
                    <option value="22">    28    </option>
                    <option value="22">    29    </option>
                    <option value="22">    30    </option>
                    <option value="22">    31    </option>
                    <option value="22">    32    </option>
                
                </select>일
            </td>
            </tr>
            <!-- 체크박스 -->
            <tr>
                <td align="center" bgcolor="D5D5D5">관심분야:</td>
                <td>
                    <input type="checkbox" name="hobby"  id="hobby"value="컴퓨터">컴퓨터
                    <input type="checkbox" name="hobby" id="hobby" value="인터넷">인터넷
                    <input type="checkbox" name="hobby" id="hobby" value="영화">영화
                    <input type="checkbox" name="hobby" id="hobby" value="여행">여행
                    <input type="checkbox" name="hobby" id="hobby" value="음악감상">음악감상
                
                </td>
            </tr>
            <tr align="center">
                <td bgcolor="D5D5D5">자기소개</td>
                <td><textarea name="intro" id="intro" style="resize: none;" cols="50" rows="8"></textarea></td>
            </tr>
    </table><br>
    <div align="center">
        <input type="submit" value="회원가입">
        <input type="reset" value="다시입력">
    </div>
</form>
</body>
</html>
cs

회원가입을 진행하고 기입한 값을 회원가입 검사 페이지로 넘긴다 

유효성 검사 들어가있다.

회원가입 검사

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import = "java.sql.*" %>
    <%@ page import="javax.sql.*"%>
    <%@ page import="javax.naming.*"%>
   
   <%@page import="java.util.*"%>
<%
/* 한글 깨짐방지 */ 
    request.setCharacterEncoding("UTF-8");
 
 
%>
   
    <%
    Connection conn =null;
    
    try{
 
         Context init = new InitialContext();
         DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
         conn = ds.getConnection();
         out.println("<h3>연결되었습니다</h3>");
        
    } catch (Exception e) {
        out.println("<h3>연결에 실패하였습니다</h3>");
        e.printStackTrace();
     } /* 데이터베이스와연결 */
  try/* 회원가입에 기입했던 내용들의 값을 받아옴 */
        String id = request.getParameter("ide");
        String pass = request.getParameter("pass");
        String mail = request.getParameter("mail");
        String name = request.getParameter("name");
        String pnum = request.getParameter("pnum");
        String nnum = request.getParameter("my_name");
        String year = request.getParameter("year");
        String mon = request.getParameter("mon");
        String day = request.getParameter("day");
        String[] hobby = request.getParameterValues("hobby"); /* 관심분야의 경우 복수 체크가 가능하도록 배열로 받는다 */
        StringBuffer ho =new StringBuffer();/* 버퍼를 생성. 버퍼에 값을 저장한다 */
        for(String i:hobby){
            ho.append(i).append("");/* append(추가하다.) */
        } 
        String intro = request.getParameter("intro");
        
        /* String sql = "insert into login(id,pass,mail,name ,pnum,my_name,year,mon,day,hobby,intro) values(?,?,?,?,?,?,?,?,?,?,?)"; */
           String sql = "insert into info(id,pass,mail,name,pnum,nnum,year,mon,day,hobby,intro) values(?,?,?,?,?,?,?,?,?,?,?)";
        /* 쿼리문, 값을 넣을 칼럼을 적고 ?를 넣어준다ㅣ */
        PreparedStatement pstmt=conn.prepareStatement(sql);
        /* 쿼리문 실행  , 앞에 적힌 번호에따라 ?위치에 맞게 들어간다.*/
        pstmt.setString(1,id);
        pstmt.setString(2,pass);
        pstmt.setString(3,mail);
        pstmt.setString(4,name);
        pstmt.setString(5,pnum);
           pstmt.setString(6,nnum);
        pstmt.setString(7,year);
        pstmt.setString(8,mon);
        pstmt.setString(9,day);
        pstmt.setString(10, ho.toString());
           pstmt.setString(11,intro);
        
        pstmt.executeUpdate();
        
        pstmt.close();
        conn.close();
    }catch(Exception e){
        out.println("<h3>연결 실패</h3>");
        e.printStackTrace();
        
    } 
    /* 회원가입끝나면 로그인 페이지로 이동 */
   response.sendRedirect("login.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=UTF-8">
<title></title>
</head>
<body>
<% %>
</body>
</html>
cs

회원가입에서 올라온 값을 데이터 베이스를 연결한후 옮긴다 

이때 테이블이 만들어져있어야한다

메인

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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ page import="javax.naming.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
    String id = null;/*  아이디를 널값으로 초기화*/
    
    if(session.getAttribute("id"!= null){ /*아이디가 있으면  */ 
        id = (String) session.getAttribute("id"); /* 널값으로 초기화된 아이디에 값을 넣음 */
    }else{/* 세션에 아이디가 없으면  로그인 페이지로 이동*/
    out.println("<script>");
    out.println("location.href='login.jsp'");
    out.println("</script>");
    }
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
    <h3><%=id%>님이 로그인하셨습니다.</h3>
    <% /*로그인 후 아이디가 admin 이면 관리자 모드로 실행  */
    if(id.equals("admin")){
    %>
    <a href = "admin-total.jsp">관리자모드</a>
    <%
    }else{
    %><!-- 아이디가 유저면 그냥 자기 것만 건들수 있도록 만듬 -->
    <a href="my_info.jsp?id=<%=id%>">내 정보 보기</a>
    <a href="fix.jsp?id=<%=id%>">내 정보 수정</a>
    <%
    }
    %>
</body>
</html>
cs

로그인 성공후 보는 페이지 관리자 아이디면 관리자 페이지를 

유저 아이디면 유저 페이지를 볼수있따.

유저 정보

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
   String id = null;
   request.setCharacterEncoding("utf-8");
 
   String info_id = request.getParameter("id"); //id를 받아옴
 
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
 
   try { //데이터 베이스에 연결
      Context init = new InitialContext();
      DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
      conn = ds.getConnection();
 
      String sql = "select * from info where id=?"//id에 대한 정보를 모두 출력
      stmt = conn.prepareStatement(sql); //sql문 출력
      stmt.setString(1, info_id);
      rs = stmt.executeQuery();
      rs.next();
 
   } catch (Exception e) {
      e.printStackTrace();
   }
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>내 정보 보기</title>
</head>
<body>
   <form>
      <table>
         <tr>
            <td>아이디</td>
            <td><%=rs.getString("id")%></td>
         </tr>
         <tr>
            <td>비밀번호</td>
            <td><%=rs.getString("pass")%></td>
         </tr>
         <tr>
            <td>이메일</td>
            <td><%=rs.getString("mail")%></td>
         </tr>
         <tr>
            <td>주민등록번호</td>
            <td><%=rs.getString("pnum")%> - <%=rs.getString("nnum")%>
            </td>
         </tr>
         <tr>
            <td>생일</td>
            <td><%=rs.getString("year")%>년 <%=rs.getString("mon")%>월 <%=rs.getString("day")%>일</td>
         </tr>
         <tr>
            <td>취미</td>
            <td><%=rs.getString("hobby")%></td>
         </tr>
         <tr>
            <td><a href="javascript:history.back()">뒤로가기</a>
         </tr>
      </table>
   </form>
</body>
</html>
cs

유저로 로그인 해서 내정보 보기를 누르면 보이는 페이지, 


관리자 로그인

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
   //String id = null;    /* 세션의 아이디가 널값이 거나 관리자가 아니면 로그인 화면으로 */
   if ((session.getAttribute("id"== null|| (!((String) session.getAttribute("id")).equals("admin"))) {
      out.println("<script>");
      out.println("location.href='login.jsp'");
      out.println("</script>");
   }
 
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
 
   try {
      Context init = new InitialContext();
      DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
      conn = ds.getConnection();
/* 디비 연결 */
      String sql = "select * from info";    /*info테이블을 호출한다  */
      stmt = conn.prepareStatement(sql);
      rs = stmt.executeQuery();
   } catch (Exception e) {
      e.printStackTrace();
   }
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>관리자 모드</title>
</head>
<body>
   <table>
      <tr>
         <td colspan="2">회원 목록</td>
      </tr>
      <%
         while (rs.next()) {
      %>
      <tr><!-- 회원의 아이디를 클릭하면 멤버 인포로 이동 정보를 볼수있다. -->
         <td><a href="member_info.jsp?id=<%=rs.getString("id")%>"<%=rs.getString("id")%></a></td>
         <td><a href="delete.jsp?id=<%=rs.getString("id")%>">삭제</a></td><!-- 아이디 삭제 -->
      </tr>
      <%
         }
      %>
      
   </table>
</body>
</html>
cs

관리자 페이볼수있다.

모든 회원의 확인 가능 회원을 클리하면 그 회원의 모든 정보열람가능, 

삭제누르면 회원 삭제

모든회원 정보 페이지

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%/* 내가 선택한 회원의 정보를 볼수있다. */
   String id = null;
   if ((session.getAttribute("id"== null|| (!((String) session.getAttribute("id")).equals("admin"))) {
      out.println("<script>");
      out.println("location.href='login.jsp'");
      out.println("</script>");
   }
 
   String info_id = request.getParameter("id");
 
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
 
   try {
      Context init = new InitialContext();
      DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
      conn = ds.getConnection();
 
      String sql = "select * from info where id=?";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, info_id);
      rs = stmt.executeQuery();
      rs.next();
 
   } catch (Exception e) {
      e.printStackTrace();
   }
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>회원 정보 보여주기</title>
</head>
<body>
   <table>
      <tr>
         <td>아이디</td>
         <td><%=rs.getString("id")%></td>
      </tr>
      <tr>
         <td>비밀번호</td>
         <td><%=rs.getString("pass")%></td>
      </tr>
      <tr>
         <td>이메일</td>
         <td><%=rs.getString("mail")%></td>
      </tr>
      <tr>
         <td>주민등록번호</td>
         <td><%=rs.getString("pnum")%> - <%=rs.getString("nnum")%>
         </td>
      </tr>
      <tr>
         <td>생일</td>
         <td><%=rs.getString("year")%>년 <%=rs.getString("mon")%>월 <%=rs.getString("day")%>일</td>
      </tr>
      <tr>
         <td>취미</td>
         <td><%=rs.getString("hobby")%></td>
      </tr>
      <tr>
         <td>자기 소개</td>
         <td><%=rs.getString("intro")%></td>
      </tr>
   </table>
</body>
</html>
cs


삭제페이지

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
   String id = null;
 
   if ((session.getAttribute("id"== null|| (!((String) session.getAttribute("id")).equals("admin"))) {
      out.println("<script>");
      out.println("location.href='login.jsp'");
      out.println("</script>");
   }
 
   String delete_id = request.getParameter("id");
    /* 삭제하기로한 아이디 값을 가지고온다. */
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
 
   try {
      Context init = new InitialContext();
      DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
      conn = ds.getConnection();
    /* 아이디를 삭제한다. */
      String sql = "delete from info where id=?";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, delete_id);
      stmt.executeQuery();
 
      out.println("<script>");
      out.println("location.href='admin-total.jsp'");    /* "삭제에 실패하면 어드민 토탈로 다시간다" */
      out.println("</script>");
      
   } catch (Exception e) {
      e.printStackTrace();
   } finally {
      try {
         stmt.close();
         conn.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>정보 삭제</title>
</head>
<body>
</body>
</html>
cs

수정1

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="javascript"
   src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script>
   function checks() {
      var hobbyCheck = false;
      var getMail = RegExp(/^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\-]+\.[A-Za-z0-9\-]+/);
      var getCheck = RegExp(/^[a-zA-Z0-9]{4,12}$/);
      var fmt = RegExp(/^\d{6}[1234]\d{6}$/); //형식 설정
 
      //비밀번호 유효성검사
      if (!getCheck.test($("#password").val())) {
         alert("형식에 맞게 입력해주세요");
         $("#password").val("");
         $("#password").focus();
         return false;
      }
 
      //비밀번호 확인란 공백 확인
      if ($("#password_check").val() == "") {
         alert("패스워드 확인란을 입력해주세요");
         $("#password_check").focus();
         return false;
      }
 
      //비밀번호 서로확인
      if ($("#password").val() != $("#password_check").val()) {
         alert("비밀번호가 상이합니다");
         $("#password").val("");
         $("#password_check").val("");
         $("#password").focus();
         return false;
      }
 
      //이메일 공백 확인
      if ($("#mail").val() == "") {
         alert("이메일을 입력해주세요");
         $("#mail").focus();
         return false;
      }
 
      //이메일 유효성 검사
      if (!getMail.test($("#mail").val())) {
         alert("이메일형식에 맞게 입력해주세요")
         $("#mail").val("");
         $("#mail").focus();
         return false;
      }
 
      //취미 유효성 검사
      for (var i = 0; i < $('[name="hobby"]').length; i++) {
         if ($('input:checkbox[name="hobby"]').eq(i).is(":checked"== true) {
            hobbyCheck = true;
            break;
         }
      }
 
      if (!hobbyCheck) {
         alert("하나이상 관심분야를 체크해 주세요");
         return false;
      }
 
      //자기소개란 공백 검사
      if ($("#intro").val() == "") {
         alert("자기소개를 입력해주세요")
         $("#intro").val("");
         $("#intro").focus();
         return false;
      }
      return true;
   }
</script>
<%
   String id = request.getParameter("id");
   request.setCharacterEncoding("utf-8");
 
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
 
   try {
      Context init = new InitialContext();
      DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
      conn = ds.getConnection();
/* 원하는 아이디의 정보만 불러온다 */
      String sql = "select * from info where id=?";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, id);
      rs = stmt.executeQuery();
      rs.next();
 
   } catch (Exception e) {
      e.printStackTrace();
   }
   
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>개인 정보 수정</title>
</head>
<body>
   <form action="fix_data.jsp" name="fix" method="post" onsubmit="return checks()">
      <table border="1" bordercolor="grey" align="center">
         <tr>
            <td colspan="2" bgcolor="lightblue" align="center">회원 기본 정보</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">아이디</td>
            <td><%=rs.getString("id")%></td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">비밀번호</td>
            <td><input size="15" type="pass" name="pass"
               id="password"> 4~12자의 영문 대소문자와 숫자로만 입력</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">비밀번호 확인</td>
            <td><input size="15" type="password" name="password_check"
               id="password_check"></td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">메일 주소</td>
            <td><input type="text" name="mail" id="mail"> 예)
               id@domain.com</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">이름</td>
            <td><%=rs.getString("name")%></td>
         </tr>
         <tr>
            <td colspan="2" bgcolor="lightblue" align="center">개인 신상 정보</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">주민등록번호</td>
            <td><%=rs.getString("pnum")%> - <%=rs.getString("nnum")%>
            </td>
         </tr>
         <tr>
            <td align="center" bgcolor="lightgrey"><b>생일</b></td>
            <td><%=rs.getString("year")%>년 <%=rs.getString("mon")%>월 <%=rs.getString("day")%>
            </td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">관심분야</td>
            <td><input type="checkbox" name="hobby" value="컴퓨터">컴퓨터
               <input type="checkbox" name="hobby" value="인터넷">인터넷 <input
               type="checkbox" name="hobby" value="여행">여행 <input
               type="checkbox" name="hobby" value="영화감상">영화감상 <input
               type="checkbox" name="hobby" value="음악감상">음악감상</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">자기소개</td>
            <td><textarea cols="50"
                  style="margin: 0px; height: 300px; width: 480px" name="intro"></textarea>
               <!--크기 조정 가능--></td>
         </tr>
         <tr>
            <td colspan="2" align="center"><input type="submit" value="수정완료"></td>
      </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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="javascript"
   src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script>
   function checks() {
      var hobbyCheck = false;
      var getMail = RegExp(/^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\-]+\.[A-Za-z0-9\-]+/);
      var getCheck = RegExp(/^[a-zA-Z0-9]{4,12}$/);
      var fmt = RegExp(/^\d{6}[1234]\d{6}$/); //형식 설정
 
      //비밀번호 유효성검사
      if (!getCheck.test($("#password").val())) {
         alert("형식에 맞게 입력해주세요");
         $("#password").val("");
         $("#password").focus();
         return false;
      }
 
      //비밀번호 확인란 공백 확인
      if ($("#password_check").val() == "") {
         alert("패스워드 확인란을 입력해주세요");
         $("#password_check").focus();
         return false;
      }
 
      //비밀번호 서로확인
      if ($("#password").val() != $("#password_check").val()) {
         alert("비밀번호가 상이합니다");
         $("#password").val("");
         $("#password_check").val("");
         $("#password").focus();
         return false;
      }
 
      //이메일 공백 확인
      if ($("#mail").val() == "") {
         alert("이메일을 입력해주세요");
         $("#mail").focus();
         return false;
      }
 
      //이메일 유효성 검사
      if (!getMail.test($("#mail").val())) {
         alert("이메일형식에 맞게 입력해주세요")
         $("#mail").val("");
         $("#mail").focus();
         return false;
      }
 
      //취미 유효성 검사
      for (var i = 0; i < $('[name="hobby"]').length; i++) {
         if ($('input:checkbox[name="hobby"]').eq(i).is(":checked"== true) {
            hobbyCheck = true;
            break;
         }
      }
 
      if (!hobbyCheck) {
         alert("하나이상 관심분야를 체크해 주세요");
         return false;
      }
 
      //자기소개란 공백 검사
      if ($("#intro").val() == "") {
         alert("자기소개를 입력해주세요")
         $("#intro").val("");
         $("#intro").focus();
         return false;
      }
      return true;
   }
</script>
<%
   String id = request.getParameter("id");
   request.setCharacterEncoding("utf-8");
 
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
 
   try {
      Context init = new InitialContext();
      DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
      conn = ds.getConnection();
/* 원하는 아이디의 정보만 불러온다 */
      String sql = "select * from info where id=?";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, id);
      rs = stmt.executeQuery();
      rs.next();
 
   } catch (Exception e) {
      e.printStackTrace();
   }
   
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>개인 정보 수정</title>
</head>
<body>
   <form action="fix_data.jsp" name="fix" method="post" onsubmit="return checks()">
      <table border="1" bordercolor="grey" align="center">
         <tr>
            <td colspan="2" bgcolor="lightblue" align="center">회원 기본 정보</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">아이디</td>
            <td><%=rs.getString("id")%></td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">비밀번호</td>
            <td><input size="15" type="pass" name="pass"
               id="password"> 4~12자의 영문 대소문자와 숫자로만 입력</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">비밀번호 확인</td>
            <td><input size="15" type="password" name="password_check"
               id="password_check"></td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">메일 주소</td>
            <td><input type="text" name="mail" id="mail"> 예)
               id@domain.com</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">이름</td>
            <td><%=rs.getString("name")%></td>
         </tr>
         <tr>
            <td colspan="2" bgcolor="lightblue" align="center">개인 신상 정보</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">주민등록번호</td>
            <td><%=rs.getString("pnum")%> - <%=rs.getString("nnum")%>
            </td>
         </tr>
         <tr>
            <td align="center" bgcolor="lightgrey"><b>생일</b></td>
            <td><%=rs.getString("year")%>년 <%=rs.getString("mon")%>월 <%=rs.getString("day")%>
            </td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">관심분야</td>
            <td><input type="checkbox" name="hobby" value="컴퓨터">컴퓨터
               <input type="checkbox" name="hobby" value="인터넷">인터넷 <input
               type="checkbox" name="hobby" value="여행">여행 <input
               type="checkbox" name="hobby" value="영화감상">영화감상 <input
               type="checkbox" name="hobby" value="음악감상">음악감상</td>
         </tr>
         <tr>
            <td bgcolor="lightgrey" align="center">자기소개</td>
            <td><textarea cols="50"
                  style="margin: 0px; height: 300px; width: 480px" name="intro"></textarea>
               <!--크기 조정 가능--></td>
         </tr>
         <tr>
            <td colspan="2" align="center"><input type="submit" value="수정완료"></td>
      </table>
   </form>
</body>
</html>
cs


1
2
3
4
5
6
7
8
9
10
11
<Context>
   <Resource name="jdbc/OracleDB" auth="Container"
      driverClassNaem="oracle.jdbc.driver.OracleDriver" 
      type="javax.sql.DataSource"
      url="jdbc:oracle:thin:@127.0.0.1:1521:orcl" 
      username="scott"
      password="tiger" 
      maxActive="20"
       maxIdle="10"
        maxWait="-1" />
</Context>
cs


'Oracle' 카테고리의 다른 글

MVC2  (0) 2018.05.02
10. 트랜젝션  (0) 2018.04.23
9.DML  (0) 2018.04.23
8.DDL  (0) 2018.04.23
7.그룹함수  (0) 2018.04.23