19join.html

19JoinFail.html

19JoinSuccess.html

ProcessJoin19.java

19login.html

19loginFail.html

19loginSuccess.html

19loginSuccess.jsp

19processLogin.jsp

19processLogout.jsp


loginLogic.zip





19join.html

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
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    <form action="ProcessJoin" method="post">
    이름 : <input type="text" name="name" size="10"><br/>
    아이디 : <input type="text" name="id" size="10"><br/>
    비밀번호 : <input type="password" name="pw" size="10"><br/>
    전화번호 : <select name="ph1">
        <option value="010">010</option>
        <option value="010">011</option>
        <option value="010">019</option>
        <option value="010">017</option>
    </select> -
    <input type="text" name="ph2" size="4"> - <input type="text" name="ph3" size="4"><br/>
    성별 : 남<input type="radio" name="gender" value ="남" size="5">여<input type="radio" name="gender" value ="여" size="5"><br/>
    <input type="submit" value="회원가입"><input type="reset" value="취소">
    
    
    </form>
 
 
</body>
</html>
cs




ProcessJoin19.java

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
package com.javalec.ex;
 
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * Servlet implementation class ProcessJoin19
 */
@WebServlet("/ProcessJoin")
public class ProcessJoin19 extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    
    private Connection conn;
    private Statement stmt;
    private String query;
    private String driver,url,uId,uPw,name,id,pw,phoneNum,gender;
    
//    String driver = "oracle.jdbc.driver.OracleDriver";
//    String url = "jdbc:oracle:thin:@localhost:1521:xe";
//    String uId ="Java_webApp";
//    String uPw ="kk5dd0ss2";
 
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProcessJoin19() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        actionDo(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        actionDo(request, response);
    }
 
    private void actionDo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        request.setCharacterEncoding("EUC-KR");
        driver = "oracle.jdbc.driver.OracleDriver";
        url = "jdbc:oracle:thin:@localhost:1521:xe";
        uId ="Java_webApp";
        uPw ="kk5dd0ss2";
        
        name = request.getParameter("name");
        id = request.getParameter("id");
        pw = request.getParameter("pw");
        phoneNum = request.getParameter("ph1"+ "-" +request.getParameter("ph2"+ "-" + request.getParameter("ph3");
        gender = request.getParameter("gender");
        
        query = "insert into member values('"
                +name+"', '"
                +id+"', '"
                +pw+"', '"
                +phoneNum+"', '"
                +gender+"')";
 
        try{
            Class.forName(driver);
            conn = DriverManager.getConnection(url, uId, uPw);
            stmt = conn.createStatement();
            int i = stmt.executeUpdate(query);
            if(i==1){
                System.out.println("insert success");
                response.sendRedirect("19JoinSuccess.html");
            }
            else{
                System.out.println("insert fail");
                response.sendRedirect("19JoinFail.html");
            }
            
        }
        catch(Exception e){
            e.printStackTrace();
            System.out.println("insert fail");
            response.sendRedirect("19JoinFail.html");
            
        }
        finally{
            try{
                if(stmt!=null)stmt.close();
                if(conn!=null)conn.close();
            }
            catch(Exception e){
                e.printStackTrace();
                
            }
        }
    
    }
}
 
cs



19JoinFail.html

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    회원가입에 실패하셨습니다 다시 작성해주세요.
    <a href="19join.html">
        <h2>돌아가기</h2>
    </a>
</body>
</html>
cs




19JoinSuccess.html

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    회원가입에 성공했습니다. 로그인 페이지로 이동해주세요.
    <a href="19login.html">
        <h2>로그인 페이지로 이동</h2>
    </a>
</body>
</html>
cs




19login.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    <form action="19processLogin.jsp" method="post">
        아이디 : <input type="text" name="id" size="10"><br/>
        비밀번호 : <input type="password" name="pw" size="10"><br/>
        <input type="submit" value="로그인"><input type="reset" value="취소">
    </form>
    
    <form action="19join.html" method="get">
        <input type="submit" value="회원가입">
    </form>
    
</body>
</html>
cs




19processLogin.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
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
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
 
<%!
    Connection conn;
    Statement stmt;
    ResultSet rSet;
    
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:xe";
    String uId ="Java_webApp";
    String uPw ="kk5dd0ss2";
    String id,pw,query,result;
%>
 
 
<!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>
    
    <!-- Driver load -->
    <%
    
        request.setCharacterEncoding("EUC-KR");
        driver = "oracle.jdbc.driver.OracleDriver";
        url = "jdbc:oracle:thin:@localhost:1521:xe";
        uId ="Java_webApp";
        uPw ="kk5dd0ss2";
        
        id = request.getParameter("id");
        pw = request.getParameter("pw");
        
        query = "select pw from member where id='" + id + "'";
        System.out.println(query);
        
        try{
            Class.forName(driver);
            conn = DriverManager.getConnection(url, uId, uPw);
            stmt = conn.createStatement();
            rSet = stmt.executeQuery(query);
            
            while(rSet.next()){
                result = rSet.getString("pw");
            }
            
            if(result == null){
                System.out.println("login fail");
                response.sendRedirect("19loginFail.html");
            }
            else{
                System.out.println("pw : "+pw);
                System.out.println("result : "+result);
                if(result.equals(pw)){
                    session.setAttribute("id", id);
                    session.setAttribute("pw", pw);
                    System.out.println("login success");
                    response.sendRedirect("19loginSuccess.jsp");
                }
                else{
                    System.out.println("password is not matched");
                    response.sendRedirect("19loginFail.html");
                }
            }
    
            
        }
        catch(Exception e){
            e.printStackTrace();
            System.out.println("login fail");
            response.sendRedirect("19loginFail.html");
            
        }
        finally{
            try{
                if(rSet!=null){rSet.close();}
                if(stmt!=null){stmt.close();}
                if(conn!=null){conn.close();}
            }
            catch(Exception e){
                e.printStackTrace();
                
            }
        }
        
        
    
    
    
    
    %>
 
</body>
</html>
cs



 session.setAttribute("id", id);session.setAttribute("pw", pw);

:세션에 로그인 정보를 주고 다른 로그인 페이지에서 유저가 로그인을 한 후 접속하는건지 그렇지 않은지를 세션을 통해 관리한다. 만약.로그인을 성공하지 않고도 login성공화면을 get으로 받으려고 한다면 문제가 되기때문이다.



19loginSuccess.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
<%@ 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>Insert title here</title>
</head>
<body>
 
    <%
    try{
        Object id = session.getAttribute("id");
        Object pw = session.getAttribute("pw");
        
        out.println(id.toString() + "님 접속을 환영합니다");%>
        <form action="19processLogout.jsp" method="post">
            <input type="submit" value="로그아웃">
        </form>
    <%}
    catch(NullPointerException e){
        e.printStackTrace();
        out.println("올바른 경로로 엑세스해주세요");    
    }
 
 
    %>
 
</body>
</html>
cs


 Object id = session.getAttribute("id");Object pw = session.getAttribute("pw");

:세션을 통해 로그인 정보를 받고, 세션에 있는 로그인 정보와 사용자의 정보가 같을시에만 페이지를 렌더링하는 로직을 취할 수 있을 것이다. 


19processLogout.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<%@ 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>Insert title here</title>
</head>
<body>
    <%
    session.invalidate();
    %>
    
    logout되었습니다.
</body>
</html>
cs


session.invalidate();

: 세션 객체에 저장되어 있는 세션을 제거한다.















+ Recent posts