'회원가입'에 해당되는 글 3건

  1. 2019.09.17 회원 가입시 아이디 중복 확인 추가 (내 프로젝트에 적용)
  2. 2019.08.06 Spring 회원가입시 이메일 인증 후 회원가입 12
  3. 2019.05.07 19.05.07 회원가입 및 로그인 페이지 만들기

회원 가입시 아이디 중복 확인 추가 (내 프로젝트에 적용)

Back-End/Spring 2019. 9. 17. 13:59
728x90
반응형

회원가입 페이지에서 아이디 "중복확인" 버튼을 누르면 중복된 아이디가 있을시에는 경고창이 출력되고,


중복된 아이디가 없을시에는 아이디를 사용할 수 있다고 출력됨.



join.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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<%@ include file="../include/header.jsp"%>
<%@ include file="../include/menu.jsp"%><br>
<!-- 회원가입 페이지 -->
<body>
<center>
<table border="1" width="450" height="400">
    
        <br> <br>
        <center>
        <span style="color: green; font-weight: bold;">회원가입</span> <br> <br>
        
        <div style="text-align:center;">
            <tr>        
                <td>
                    
                        <!-- 받아온 아이디가 없을때, 즉 처음 이 페이지가 출력되었을 때-->
                        
                        <c:if test = "${user_id == null}">
                        <form action="join_id_check.do${e_mail}" method="post">
                    <center>
                        <div>    
                            아이디 : <input type="text" name="user_id" placeholder="  ID를 입력하세요. ">  <button type="submit" name="submit">중복확인</button>
                            
                            
                                                    
                        </div>
                        <br>
                        <div>
                            비밀번호 : <input type="password" name="member_pass"
                                placeholder="  비밀번호를 입력하세요. ">
                        </div>
                        <br>
                        <div>
                            인증받은 이메일 : ${e_mail}
                        </div>                        
                        
                        <!-- 이메일은 인증받은 이메일을 사용해야 하므로 컨트롤러에서 이메일을 가져와서 사용함 -->
                        <!-- 가져온후에 다시 컨트롤러로 넘긴후에 db에 저장하는 식으로 진행 -->
                        
                        <br> <br>
                        <button type="submit" name="submit">회원가입</button>
                    </center>
                        </div>
                    </td>
                </tr>
            </table>
            </center>
        </form>
                            </c:if>

                     <!-- 아이디 중복확인을 한 후에 아이디를 받아왔을 경우에 출력되는 부분 -->

                        <c:if test = "${user_id != null}">
                        <form action="join_check.do${user_id},${e_mail}" method="post">
                    <center>
                        <div>
                            아이디 : ${user_id}
                                                    
                        </div>
                        <br>
                        <div>
                            비밀번호 : <input type="password" name="member_pass"
                                placeholder="  비밀번호를 입력하세요. ">
                        </div>
                        <br>
                        <div>
                            인증받은 이메일 : ${e_mail}
                        </div>                        
                        
                        <!-- 이메일은 인증받은 이메일을 사용해야 하므로 컨트롤러에서 이메일을 가져와서 사용함 -->
                        <!-- 가져온후에 다시 컨트롤러로 넘긴후에 db에 저장하는 식으로 진행 -->
                        
                        <br> <br>
                        <button type="submit" name="submit">회원가입</button>
                    </center>
                        </div>
                    </td>
                </tr>
            </table>
            </center>
        </form>
                            </c:if>    
        </center>
<br><br><%@ include file="../include/Botton.jsp"%>
</body>
</html>
cs




MemberController.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
//id 중복확인을 하는 메소드
    @RequestMapping("/member/join_id_check.do{e_mail}")
    public ModelAndView id_check(String user_id, HttpServletResponse response_equals, @PathVariable String e_mail) throws Exception    {
        
        
        memberservice.join_id_check(user_id);
        
    //id가 기존 db에 저장되어 있지 않을 경우 실행되는 부분
    if(memberservice.join_id_check(user_id)) {
        
        response_equals.setContentType("text/html; charset=UTF-8");
        PrintWriter out_equals = response_equals.getWriter();
        out_equals.println("<script>alert('사용하실 수 있는 아이디 입니다.');</script>");
        out_equals.flush();
        
        ModelAndView mv = new ModelAndView();
        
        mv.setViewName("/member/join");
        
        mv.addObject("e_mail", e_mail);
        
        mv.addObject("user_id",user_id);
        
        return mv;
        
    //id가 기존 db에 저장되어 있을 경우 id가 중복된 것으므로 이쪽 구문이 실행된다.
    
else {

        response_equals.setContentType("text/html; charset=UTF-8");

        PrintWriter out_equals = response_equals.getWriter();

        out_equals.println("<script>alert('사용할 수 없는 아이디 입니다. 다른 아이디를 입력해주세요.'); history.go(-1);</script>");
        
out_equals.flush();
        
    }
    
    ModelAndView mv = new ModelAndView();

    mv.setViewName("/member/join");
    
        return mv;
    }

cs



MemberServiceImpl.java 중 일부


1
2
3
4
5
6
7
8

//아이디 중복 확인
    @Override
    public boolean join_id_check(String user_id) throws Exception {
    
//참, 거짓을 판별해서 리턴함
        boolean result = memberdao.join_id_check(user_id);
        
        return result;
    }
cs



MemberDAOImpl.java 중 일부


삼항 연산자를 사용해서 user의 id가 기존에 저장되어 있는 데이터라면 false를 리턴하고,


기존에 저장되어 있지 않은 데이터라면 true를 리턴하게 한다.


1
2
3
4
5
6
7
8
9
@Override
    public boolean join_id_check(String user_id) throws Exception {
 
        String user_id1 = sqlSession.selectOne("member.join_id_check", user_id);
    
        //조건식 ? true일때의 값 : false일때의 값

        return (user_id1==null) ? true : false;
    }
    
cs



MemberMapper.xml 중 일부


1
2
3
4
5
    
<!-- 아이디 중복확인 관련 mapper-->

    <select id = "join_id_check" resultType = "String" >
        select user_id from member
        where user_id=#{user_id}

    </select>       
cs




728x90
반응형
:

Spring 회원가입시 이메일 인증 후 회원가입

Back-End/Spring 2019. 8. 6. 15:58
728x90
반응형

 

 기본 구조


 1. 메인페이지에서 "회원가입" 을 클릭


 2. 이메일 인증 페이지에서 이메일을 작성후 인증코드 전송 버튼을 클릭


 3. 입력한 이메일에 들어가서 메일로 도착한 인증코드를 인증코드 입력창에 입력함


 4. 인증코드가 맞으면 회원가입 창으로 이동하고, 인증코드가 틀리면 경고창을 출력한 후에 다시 입력하게 한다.





1. pom.xml에 이메일 관련 라이브러리를 추가함


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!-- 메일 전송 -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
    
    
    <!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.6.2</version>
</dependency>
    
    
    <dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>
cs




2. root-context.xml에 사용할 이메일에 대한 빈 작성 (나같은 경우는 gmail을 사용함)


1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- Gmail -->
  <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com" />
    <property name="port" value="587" />
    <property name="username" value="아이디@gmail.com" />
    <property name="password" value="비밀번호" />
    <property name="javaMailProperties">
    <props>
      <prop key="mail.smtp.auth">true</prop>
      <prop key="mail.smtp.starttls.enable">true</prop>
    </props>
    </property>
  </bean>
cs




3. view 파일들 작성


email.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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
 
 
<table border="1" width="300" height="300" align"center">
<center>
<span style="color: green; font-weight: bold;">이메일 인증 (이메일을 인증 받아야 다음 단계로 넘어갈 수 있습니다.)</span> <br> <br>    
        <br> <br>
        
        
 
        
        <div style="text-align:center;">
            <tr>        
                <td>
                <center>
                    <form action="auth.do" method="post">
                    
                    <center>
                        <br>
                        <div>
                            이메일 : <input type="email" name="e_mail"
                                placeholder="  이메일주소를 입력하세요. ">
                        </div>                                                    
 
                        <br> <br>
                        <button type="submit" name="submit">이메일 인증받기 (이메일 보내기)</button>
 
                        </div>
                    </td>
                </tr>
                    </center>
            </table>
        </form>
</center>
 
</body>
</html>
cs




email_injeung.jsp (인증번호를 입력하는 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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<table border="1" width="300" height="300" align"center">
<center>
<span style="color: green; font-weight: bold;">입력한 이메일로 받은 인증번호를 입력하세요. (인증번호가 맞아야 다음 단계로 넘어가실 수 있습니다.)</span> <br> <br>    
        <br> <br>
        
        
        <div style="text-align:center;">
            <tr>        
                <td>
                <center>
                    <form action="join_injeung.do${dice}" method="post"> //받아온 인증코드를 컨트롤러로 넘겨서 일치하는지 확인                  
                    <center>
                        <br>
                        <div>
                            인증번호 입력 : <input type="number" name="email_injeung"
                                placeholder="  인증번호를 입력하세요. ">
                        </div>                                        
 
                        <br> <br>
                        <button type="submit" name="submit">인증번호 전송</button>
 
                        </div>
                    </td>
                </tr>
                    </center>
            </table>
        </form>
</center>
 
 
</body>
</html>
cs




4. 컨트롤러 작성 (MemberController.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
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
@Controller    //컨트롤러 빈 선언
public class MemberController {
    
    
    @Inject    //서비스를 호출하기 위해서 의존성을 주입
    JavaMailSender mailSender;     //메일 서비스를 사용하기 위해 의존성을 주입함.
    MemberService memberservice; //서비스를 호출하기 위해 의존성을 주입
    
    
    
    
    //로깅을 위한 변수
    private static final Logger logger=
    LoggerFactory.getLogger(MemberController.class);
    private static final String String = null;
    
    
    // mailSending 코드
        @RequestMapping( value = "/member/auth.do" , method=RequestMethod.POST )
        public ModelAndView mailSending(HttpServletRequest request, String e_mail, HttpServletResponse response_email) throws IOException {
 
            Random r = new Random();
            int dice = r.nextInt(4589362+ 49311; //이메일로 받는 인증코드 부분 (난수)
            
            String setfrom = "dlgkstjq623@gamil.com";
            String tomail = request.getParameter("e_mail"); // 받는 사람 이메일
            String title = "회원가입 인증 이메일 입니다."// 제목
            String content =
            
            System.getProperty("line.separator")+ //한줄씩 줄간격을 두기위해 작성
            
            System.getProperty("line.separator")+
                    
            "안녕하세요 회원님 저희 홈페이지를 찾아주셔서 감사합니다"
            
            +System.getProperty("line.separator")+
            
            System.getProperty("line.separator")+
    
            " 인증번호는 " +dice+ " 입니다. "
            
            +System.getProperty("line.separator")+
            
            System.getProperty("line.separator")+
            
            "받으신 인증번호를 홈페이지에 입력해 주시면 다음으로 넘어갑니다."// 내용
            
            
            try {
                MimeMessage message = mailSender.createMimeMessage();
                MimeMessageHelper messageHelper = new MimeMessageHelper(message,
                        true"UTF-8");
 
                messageHelper.setFrom(setfrom); // 보내는사람 생략하면 정상작동을 안함
                messageHelper.setTo(tomail); // 받는사람 이메일
                messageHelper.setSubject(title); // 메일제목은 생략이 가능하다
                messageHelper.setText(content); // 메일 내용
                
                mailSender.send(message);
            } catch (Exception e) {
                System.out.println(e);
            }
            
            ModelAndView mv = new ModelAndView();    //ModelAndView로 보낼 페이지를 지정하고, 보낼 값을 지정한다.
            mv.setViewName("/member/email_injeung");     //뷰의이름
            mv.addObject("dice", dice);
            
            System.out.println("mv : "+mv);
 
            response_email.setContentType("text/html; charset=UTF-8");
            PrintWriter out_email = response_email.getWriter();
            out_email.println("<script>alert('이메일이 발송되었습니다. 인증번호를 입력해주세요.');</script>");
            out_email.flush();
            
            
            return mv;
            
        }
    
    //이메일 인증 페이지 맵핑 메소드
    @RequestMapping("/member/email.do")
    public String email() {
        return "member/email";
    }
    
    
    //이메일로 받은 인증번호를 입력하고 전송 버튼을 누르면 맵핑되는 메소드.
    //내가 입력한 인증번호와 메일로 입력한 인증번호가 맞는지 확인해서 맞으면 회원가입 페이지로 넘어가고,
    //틀리면 다시 원래 페이지로 돌아오는 메소드
    @RequestMapping(value = "/member/join_injeung.do{dice}", method = RequestMethod.POST)
    public ModelAndView join_injeung(String email_injeung, @PathVariable String dice, HttpServletResponse response_equals) throws IOException {
 
        
        
        
        System.out.println("마지막 : email_injeung : "+email_injeung);
        
        System.out.println("마지막 : dice : "+dice);
        
//페이지이동과 자료를 동시에 하기위해 ModelAndView를 사용해서 이동할 페이지와 자료를 담음
        ModelAndView mv = new ModelAndView();
        
        mv.setViewName("/member/join.do");
        
        mv.addObject("e_mail",email_injeung);
        
        if (email_injeung.equals(dice)) {
            
            //인증번호가 일치할 경우 인증번호가 맞다는 창을 출력하고 회원가입창으로 이동함
            
            
            
            mv.setViewName("member/join");
            
            mv.addObject("e_mail",email_injeung);
            
            //만약 인증번호가 같다면 이메일을 회원가입 페이지로 같이 넘겨서 이메일을
            //한번더 입력할 필요가 없게 한다.
            
            response_equals.setContentType("text/html; charset=UTF-8");
            PrintWriter out_equals = response_equals.getWriter();
            out_equals.println("<script>alert('인증번호가 일치하였습니다. 회원가입창으로 이동합니다.');</script>");
            out_equals.flush();
    
            return mv;
            
            
        }else if (email_injeung != dice) {
            
            
            ModelAndView mv2 = new ModelAndView(); 
            
            mv2.setViewName("member/email_injeung");
            
            response_equals.setContentType("text/html; charset=UTF-8");
            PrintWriter out_equals = response_equals.getWriter();
            out_equals.println("<script>alert('인증번호가 일치하지않습니다. 인증번호를 다시 입력해주세요.'); history.go(-1);</script>");
            out_equals.flush();
            
    
            return mv2;
            
        }    
    
        return mv;
        
    }
cs




5. MailHandler.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
package com.example.hansub_project;
 
import java.io.UnsupportedEncodingException;
 
import javax.activation.DataSource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
 
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
 
public class MailHandler {
    
    
    private JavaMailSender mailSender;
    private MimeMessage message;
    private MimeMessageHelper messageHelper;
 
 
    public MailHandler(JavaMailSender mailSender) throws MessagingException {
        this.mailSender = mailSender;
        message = this.mailSender.createMimeMessage();
        messageHelper = new MimeMessageHelper(message, true"UTF-8");
    }
 
 
    public void setSubject(String subject) throws MessagingException {
        messageHelper.setSubject(subject);
        
        // 이메일 타이틀 
    }
    
    public void setText(String htmlContent) throws MessagingException {
        messageHelper.setText(htmlContent, true);
        
        //  이메일 TEXT 부분 
    }
    
    public void setFrom(String email, String name) throws UnsupportedEncodingException, MessagingException {
        messageHelper.setFrom(email, name);
        // 보내는 사람 이메일 
    }
    
    public void setTo(String email) throws MessagingException {
        messageHelper.setTo(email);
        //받는 사람 이메일 
    }
    
    public void addInline(String contentId, DataSource dataSource) throws MessagingException {
        messageHelper.addInline(contentId, dataSource);
    }
    
    public void send() {
        try {
            mailSender.send(message);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
cs




6. MemberDTO


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
package com.example.hansub_project.model.member.dto;
 
import java.util.Date;
 
public class MemberDTO {
    
    private String user_id;    //아이디
    private String member_pass;    //비밀번호
    private String e_mail;    //이메일
    private Date join_date;    //가입일자
    
    
    
    public String getUser_id() {
        return user_id;
    }
    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }
    public String getMember_pass() {
        return member_pass;
    }
    public void setMember_pass(String member_pass) {
        this.member_pass = member_pass;
    }
    public String getE_mail() {
        return e_mail;
    }
    public void setE_mail(String e_mail) {
        this.e_mail = e_mail;
    }
    public Date getJoin_date() {
        return join_date;
    }
    public void setJoin_date(Date join_date) {
        this.join_date = join_date;
    }
    
    
    @Override
    public String toString() {
        return "MemberDTO [user_id=" + user_id + ", member_pass=" + member_pass + ", e_mail=" + e_mail + ", join_date="
                + join_date + "]";
    }
    
 
}
 
cs




7. 서비스 , dao, mapper


MemberService.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
package com.example.hansub_project.service.member;
 
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import com.example.hansub_project.model.member.dto.MemberDTO;
 
 
public interface MemberService {
        
    
    public void join (Map<String, Object>map,MemberDTO dto); //회원가입 관련
    
    
    public boolean loginCheck(MemberDTO dto, HttpSession session);    //로그인 관련
    
    
    public String find_idCheck(MemberDTO dto);    //아이디 찾기 관련
    
    
    public String find_passCheck(MemberDTO dto);    //비밀번호 찾기 관련
    
    
    public void authentication(MemberDTO dto);        //회원 인증관련 메소드
    
    
    public void pass_change(Map<String, Object> map, MemberDTO dto)throws Exception;    //비밀번호 변경
    
    
    public boolean email_check(String e_mail) throws Exception;    //이메일 중복확인을 하는 메소드
    
    
    public boolean join_id_check(String user_id) throws Exception;    //회원가입시 아이디를 체크하는 메소드
    
    
    public List<MemberDTO> member_profile(String user_id) throws Exception;    //회원의 프로필을 볼 수 있는 메소드
    
    
 
}
 
cs




MemberServiceImpl.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
package com.example.hansub_project.service.member;
 
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
 
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.example.hansub_project.MailHandler;
import com.example.hansub_project.model.member.dao.MemberDAO;
import com.example.hansub_project.model.member.dto.MemberDTO;
 
@Service //서비스 빈 선언
public class MemberSerivceImpl implements MemberService {
 
    
    @Inject    
    MemberDAO memberdao; //dao를 사용하기 위해 의존성을 주입
    private JavaMailSender mailSender;
 
    
    
    @Override    //회원가입 메소드, Map과 dto를 갖이 넘김
    public void join(Map<String, Object>map,MemberDTO dto) {
        memberdao.join(map,dto);
 
    }
 
 
    @Override    //로그인 관련 메소드 (세션에 아이디와 비밀번호를 저장)
    public boolean loginCheck(MemberDTO dto, HttpSession session) {
        
        boolean result = memberdao.loginCheck(dto);
        if(result) {    //로그인 성공
            session.setAttribute("user_id", dto.getUser_id());
            session.setAttribute("member_pass", dto.getMember_pass());
            System.out.println(session.getAttribute("user_id"));
            System.out.println(session.getAttribute("member_pass"));
        }
        
        return result;
    }
 
    //아이디 찾기
    @Override
    public String find_idCheck(MemberDTO dto) {
        String id = memberdao.find_idCheck(dto);
        
        return id;
    }
 
    //비밀번호 찾기
    @Override
    public String find_passCheck(MemberDTO dto) {
        String pass = memberdao.find_passCheck(dto);
        return pass;
    }
 
 
    @Override
    public void authentication(MemberDTO dto) {
        
        memberdao.authentication(dto);
    }
 
 
    @Override
    public void pass_change(Map<String, Object> map, MemberDTO dto) throws Exception {
        
        
        memberdao.pass_change(map,dto);
    }
 
 
    //이메일 중복 확인
    @Override
    public boolean email_check(String e_mail) throws Exception{
        
        boolean result = memberdao.email_check(e_mail);
        
        return result;
        
    }
 
    //아이디 중복 확인
    @Override
    public boolean join_id_check(String user_id) throws Exception {
    
        boolean result = memberdao.join_id_check(user_id);
        
        return result;
    }
 
 
    //자신의 프로필을 볼 수 있게 하는 메소드
    @Override
    public List<MemberDTO> member_profile(String user_id) throws Exception{
        
        return memberdao.member_profile(user_id);
    }
    
 
    
}
cs




MemberDAO.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
package com.example.hansub_project.model.member.dao;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.example.hansub_project.model.member.dto.MemberDTO;
 
public interface MemberDAO {
 
    public void join(Map<String, Object>map,MemberDTO dto);     //회원가입 관련
    
    public boolean loginCheck(MemberDTO dto);        //로그인 관련
    
    public String find_idCheck(MemberDTO dto);        //아이디 찾기
    
    public String find_passCheck(MemberDTO dto);    //비밀번호 찾기
 
    public void authentication(MemberDTO dto);        //소셜 로그인 회원인증 관련 메소드
 
    public void pass_change(Map<String, Object> map, MemberDTO dto)throws Exception;    //비밀번호 변경
 
    public boolean email_check(String e_mail) throws Exception;    //이메일 중복 확인
 
    public boolean join_id_check(String user_id)throws Exception;    //아이디 중복 확인
 
    public List<MemberDTO> member_profile(String user_id) throws Exception;    //회원의 프로필 정보를 확인할 수 있는 메소드
    
}
 
cs




MemberDAOImpl.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
112
113
114
package com.example.hansub_project.model.member.dao;
 
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.inject.Inject;
import javax.mail.Session;
 
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
 
import com.example.hansub_project.model.member.dto.MemberDTO;
 
 
@Repository
public class MemberDAOImpl implements MemberDAO {
 
    
    @Inject
    SqlSession sqlSession;
    
    
    //회원가입 관련 메소드
    @Override
    public void join(Map<String, Object>map, MemberDTO dto) {
 
        map.get("user_id");
        map.get("member_pass");
        map.get("e_mail");
        
        sqlSession.insert("member.insertUser",map);        
    }
    
    
    //로그인관련 메소드
    @Override
    public boolean loginCheck(MemberDTO dto) {
        String name
            =sqlSession.selectOne("member.login_check", dto);
        
        //조건식 ? true일때의 값 : false일때의 값
        return (name==null) ? false : true;
    }
 
    
    //아이디 찾기 관련 메소드
    @Override
    public String find_idCheck(MemberDTO dto) {
        String id = sqlSession.selectOne("member.find_id_check", dto);
        return id;
        
    }
 
    
    //비밀번호 찾기 관련 메소드
    @Override
    public String find_passCheck(MemberDTO dto) {
        String pass = sqlSession.selectOne("member.find_pass_check", dto);
        return pass;
    }
 
    
    //회원 인증 관련 메소드
    //버튼을 클릭한 회원의 정보를 회원 테이블에 저장해서 사용할 수 있게 함
    @Override
    public void authentication(MemberDTO dto) {
        
        sqlSession.insert("member.authentication", dto);
        
    }
 
 
    @Override
    public void pass_change(Map<String, Object> map, MemberDTO dto)throws Exception{
        
        map.get("member_pass");
        map.get("e_mail");
 
        sqlSession.update("member.pass_change", map);
    }
 
 
    @Override
    public boolean email_check(String e_mail) throws Exception {
        String email
        =sqlSession.selectOne("member.email_check", e_mail);
    
        //조건식 ? true일때의 값 : false일때의 값
        return (email==null) ? true : false;
        
    }
 
 
    @Override
    public boolean join_id_check(String user_id) throws Exception {
        String user_id1
        =sqlSession.selectOne("member.join_id_check", user_id);
    
        //조건식 ? true일때의 값 : false일때의 값
        return (user_id1==null) ? true : false;
    }
 
    
    //회원의 프로필 정보를 리턴한다.
    @Override
    public List<MemberDTO> member_profile(String user_id) throws Exception {
        
        return sqlSession.selectList("member.member_profile", user_id);
    }
    
}
 
cs




memberMapper.xml


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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<!-- 다른 mapper와 중복되지 않도록 네임스페이스 기재 -->
<!-- 회원가입 -->
<mapper namespace="member">
    
    <!-- 회원가입 mapper -->
    <insert id="insertUser" parameterType="hashMap">
    insert into member (USER_ID, MEMBER_PASS, E_MAIL)
    values (#{user_id}, #{member_pass}, #{e_mail})
    </insert>
    
    
    <!-- 로그인 관련 mapper-->
    <select id = "login_check" parameterType=
    "com.example.hansub_project.model.member.dto.MemberDTO"
    resultType="String">
        select user_id from member
        where user_id=#{user_id} and member_pass=#{member_pass}
    </select>    
    
    
    <!-- 아이디 찾기 관련 mapper -->
    <select id = "find_id_check" parameterType=
    "com.example.hansub_project.model.member.dto.MemberDTO"
    resultType="String">
        select user_id from member
        where e_mail=#{e_mail}
    </select>
    
    <!-- 비밀번호 찾기 관련 mapper -->
    <select id = "find_pass_check" parameterType=
    "com.example.hansub_project.model.member.dto.MemberDTO"
    resultType="String">
        select member_pass from member
        where user_id=#{user_id} and e_mail=#{e_mail}
    </select>
    
    
    <!-- 소셜 로그인 관련 mapper -->
    <!-- 소셜 로그인 한 후에 회원 인증 버튼을 누르면 소셜 로그인 api에서 받아온 정보를 데이터 베이스의 member테이블에 저장하도록 하는 쿼리 -->
    <insert id="authentication" parameterType="com.example.hansub_project.model.member.dto.MemberDTO">
    insert into member (USER_ID, MEMBER_PASS, E_MAIL)
    values (#{user_id}, 0, #{e_mail})
    </insert>
    
    
    <!-- 비밀번호 변경 관련 mapper -->
    <update id = "pass_change" parameterType="hashMap">
    update member set member_pass=#{member_pass} where e_mail=#{e_mail}
    </update>
    
    
    <!-- 이메일 중복확인 관련 mapper-->
    <select id = "email_check" resultType="String">
        select e_mail from member
        where e_mail=#{e_mail}
    </select>
    
    
    <!-- 아이디 중복확인 관련 mapper-->
    <select id = "join_id_check" resultType="String">
        select user_id from member
        where user_id=#{user_id}
    </select>        
    
    
    <!-- 회원 프로필 확인 mapper -->
    <select id = "member_profile" resultType="com.example.hansub_project.model.member.dto.MemberDTO">
    select user_id, e_mail, join_date
    from member
    where user_id=#{user_id}
    </select>
    
    
</mapper>
 
cs






728x90
반응형
:

19.05.07 회원가입 및 로그인 페이지 만들기

Back-End/JSP 2019. 5. 7. 12:16
728x90
반응형



-소스 목록-


JSP

 * login.jsp (로그인 페이지)

 * loginProc.jsp (로그인 처리 페이지)

 * logout.jsp (로그아웃 처리 페이지)

 * member.jsp (회원가입 페이지)

 * memberProc.jsp (회원가입 처리 페이지)

 * idCheck.jsp (중복 아이디 체크 페이지)

 * zipSearch.jsp (우편번호 검색 페이지)

 기타

 * script.css (스타일 시트 파일)

 * script.js (자바스크립트 처리 파일)

 자바빈즈

 1. MemberBean.java (회원가입 및 자바빈즈)

 2. ZipcodeBean.java (우편번호 및 주소 자바빈즈)

 3. MemberMgr.java (회원 인증 및 가입과 우편번호 처리 자바 파일)

 4. DBConnectionMgr.java (데이터베이스 연결 connectionpool 자바 파일) (컴파일 순서 : 1->2->3->4)




  회원인증 및 가입의 기능


 * 회원가입 폼으로 회원의 정보를 회원테이블에 저장

 * 회원 가입 시 ID 중복 검사 기능이 있습니다.

 * 주민등록번호 인증 검사 기능이 있습니다.

 * 이메일 형식 확인 기능이 있습니다.

 * 우편번호 검색 후 자동으로 주소 저장 기능이 있습니다.

 * 회원인증 (로그인) 후 회원만의 제한적인 기능을 이용할 수 있습니다.


 

-예제 및 출력결과-

 

 

-회원 테이블 만들기-

1
2
3
4
5
6
7
8
9
10
11
12
13
CREATE TABLE tblMember(
id CHAR(20NOT NULL,
pwd CHAR(20NOT NULL,
name CHAR(20NOT NULL,
gender CHAR(1NOT NULL,
birthday CHAR(6NOT NULL,
email CHAR(30NOT NULL,
zipcode CHAR(5NOT NULL,
address CHAR(50NOT NULL,
hobby CHAR(5NOT NULL,
job CHAR(20NOT NULL,
PRIMARY KEY (id)
);
cs

 

 

-우편번호 테이블 만들기-

 
 
cs
1
2
3
4
5
6
CREATE TABLE tblZipcode (
zipcode CHAR(5NOT NULL,
AREA1 CHAR(10DEFAULT NULL,
AREA2 CHAR(20DEFAULT NULL,
AREA3 CHAR(30DEFAULT NULL)
ENGINE=InnoDB DEFAULT CHARSET=UTF8; #한글깨짐 방지 코드(문자셋 설정)
cs

 


member.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
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
<%@ page language="java" contentType="text/html; charset=EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>회원가입</title>
<link href="style.css" rel="stylesheet" type="text/css">
<!-- 회원가입 디자인 설정 -->
<!-- 자바 스크립트 문법을 사용하기 위해 타입설정 -->
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
    function idCheck(id) { //idCheck(id) 함수는 id중복확인 버튼을 클릭하면 호출되는 함수
        frm = document.regFrm; //버튼을 클릭했을 때 회원가입 폼에 아이디 값이 없으면 경고 메시지가 뜨지만 정상적으로 입력하면
        //ID 중복체크(idCheck.jsp)로 아이디 값과 함께 넘어간다.
        if (id == "") {
            alert("아이디를 입력해 주세요.");
            frm.id.focus();
            return;
        }
        url = "idCheck.jsp?id=" + id;
        window.open(url, "IDCheck""width=300,height=150");
    }
 
    function zipCheck() //zipCheck()는 우편번호찾기 버튼을 클릭하면 호출되는 함수입니다. 버튼을 클릭하면 우편번호검색
    { //(zipSearch.jsp) 페이지의 새로운 창이 만들어지면서 y라는 check값을 가지고 넘어갑니다.
        url = "zipSearch.jsp?check=n";
        widow.open(url, "ZipCodeSearch""width=500,height=300,scrollbars=yes");
    }
</script>
</head>
<body bgcolor="FFFFCC" onLoad="regFrm.id.focus()">
    <!-- 페이지 로딩 및 새로고침이 발생되면 포커스가 ID입력란으로 위치합니다. -->
    <div align="center">
        <br /> <br />
        <form name="regfrm" method="post" action="memberProc.jsp">
            <!--memberProc.jsp파일에 regfrm이라는 폼으로 post방식으로 값을 전달한다. -->
            <table align="center" border="0" cellspacing="0" cellpadding="5">
                <!-- cellspacing는 테이블의 외곽과 셸의 경계면의 두께를 설정, cellpadding는 셸과 내용의 사이를 지정하는 태그 -->
 
 
                <tr>
                    <td align="center" valign="middle" bgcolor="#FFFFCC">
                        <table border="1" cellspacing="0" cellpadding="2" align="center"
                            width="600">
                            <tr align="center" bgcolor="#996600">
                                <td colspan="3"><font color="#FFFFFF"><b>회원 가입</b></font></td>
                            </tr>
 
 
                            <tr>
                                <td width="20%">아이디</td>
                                <td width="50%"><input name="id" size="15"> <input
                                    type="button" value="ID중복확인"
                                    onClick="idCheck(this.form.id.value)"></td>
                                <!-- onClick로 입력한 아이디가 중복된 값인지 확인 -->
                                <td width="30%">아이디를 적어 주세요.</td>
                            </tr>
 
                            <tr>
                                <td>패스워드</td>
                                <td><input type="password" name="pwd" size="20"></td>
                                <td>패스워드를 적어주세요.</td>
                            </tr>
 
                            <tr>
                                <td>패스워드 확인</td>
                                <td><input type="password" name="repwd" size="20"></td>
                                <td>패스워드를 확인합니다.</td>
                            </tr>
 
                            <tr>
                                <td>이름</td>
                                <td><input name="name" size="15"></td>
                                <td>이름을 적어주세요.</td>
                            </tr>
 
                            <tr>
                                <td>성별</td>
                                <td><input type="radio" name="gender" value="1"
                                    checked="checked"> 여<input type="radio" name="gebder"
                                    value="2"></td>
                                <td>성별을 선택 하세요.</td>
                            </tr>
 
                            <tr>
                                <td>생년월일</td>
                                <td><input name="birthday" size="10"> ex)830815</td>
                                <td>생년월일을 적어 주세요.</td>
                            </tr>
 
                            <tr>
                                <td>Email</td>
                                <td><input name="email" size="30"></td>
                                <td>이메일을 적어 주세요.</td>
                            </tr>
 
                            <tr>
                                <td>우편번호</td>
                                <td><input name="zipcode" size="5" readonly> <input
                                    type="button" value="우편번호찾기" onClick="zipCheck()"> <!-- zipCheck()함수를 사용해 우편번호와 주소를 검색한다. -->
                                </td>
                                <td>우편번호를 검색하세요.</td>
                            </tr>
 
                            <tr>
                                <td>주소</td>
                                <td><input name="address" size="45"></td>
                                <td>주소를 적어 주세요.</td>
                            </tr>
 
                            <tr>
                                <td>취미</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>
                                <td>취미를 선택 하세요.</td>
                            </tr>
 
 
                            <tr>
                                <td>직업</td>
                                <td><select name=job>
                                        <option value="0" selected>선택하세요.
                                        <option value="회사원">회사원
                                        <option value="연구전문직">연구전문직
                                        <option value="교수학생">교수학생
                                        <option value="일반자영업">일반자영업
                                        <option value="공무원">공무원
                                        <option value="의료인">의료인
                                        <option value="법조인">법조인
                                        <option value="종교,언론,예술인">종교/언론/예술인
                                        <option value="농,축,수산,광업인">농/축/수산/광업인
                                        <option value="주부">주부
                                        <option value="무직">무직
                                        <option value="기타">기타
                                </select></td>
                                <td>직업을 선택 하세요.</td>
                            </tr>
 
                            <tr>
                                <td colspan="3" align="center"><input type="button"
                                    value="회원가입" onclick="inputCheck()"> &nbsp; &nbsp; <input
                                    type="reset" value="다시쓰기"> &nbsp; &nbsp; <input
                                    type="button" value="로그인"
                                    onClick="javascript:location.href='login.jsp'"></td>
                            </tr>
 
                        </table>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
cs



memberProc.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
<%@ page language="java" contentType="text/html; charset=EUC-KR"%>
<%
    request.setCharacterEncoding("EUC-KR");
%>
<jsp:useBean id="mgr" class="ch14.MemberMgr" />
<!-- 회원가입을 위한 insertMember()메소드를 사용위해 객체 생성 -->
<jsp:useBean id="bean" class="ch14.MemberBean" />
<!-- 유즈빈을 사용하여 자바빈을 사용 -->
<jsp:setProperty property="*" name="bean" />
<!-- 자바빈 객체의 프로퍼티값 변경 -->
<%
    boolean result = mgr.insertMember(bean);
    String msg = "회원가입에 실패 하였습니다.";
    String location = "member.jsp";
    if (result) {
        msg = "회원가입을 하였습니다.";
        location = "login.jsp";
    }
%>
<script>
    alert("<%=msg%>");
    location.href = "<%=location%>
    ";
</script>
cs



script.js (자바스크립트 처리 파일)

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
function inputCheck() // 회원가입버튼을 누르면 호출되는 함수 입력하지 않은값이 있으면 경고창이 뜨고 정상적으로 입력하면
                        // 회원가입이 이루어진다.
{
    if (document.regFrm.id.value == "") {
        alert("아이디를 입력해 주세요.");
        document.regFrm.id.focus();
        return;
    }
 
    if (document.regFrm.pwd.value == "") {
        alert("비밀번호를 입력해 주세요.");
        document.regFrm.pwd.focus();
        return;
    }
 
    if (document.regFrm.pwd.value == "") {
        alert("비밀번호를 확인해 주세요.");
        document.regFrm.pwd.focus();
        return;
    }
 
    if (document.regFrm.pwd.value != document.regFrm.repwd.value) // 입력한 비밀번호와
                                                                    // 확인 비밀번호가
                                                                    // 맞지 않으면 경고
                                                                    // 메시지 출력
    {
        alert("비밀번호가 일치하지 않습니다.");
        document.regFrm.repwd.value = "";
        document.regFrm.id.focus();
        return;
    }
 
    if (document.regFrm.name.value == "") {
        alert("이름을 입력해 주세요");
        document.regFrm.name.focus();
        return;
    }
 
    if (document.regFrm.birthday.value == "") {
        alert("생년월일을 입력해주세요.");
        document.regFrm.birthday.focus();
        return;
    }
 
    if (document.regFrm.email.value == "") {
        alert("이메일을 입력해 주세요.");
        document.regFrm.email.focus();
        return;
    }
 
    var str = document.regFrm.email.value;
    var atPos = str.indexOf('@');
    var atLastPos = str.lastIndexOf('@');
    var dotPos = str.indexOf('.');
    var spacePos = str.indexOf('');
    var commaPos = str.indexOf(',');
    var eMailSize = str.length;
    if (atPos > 1 && atPos == atLastPos && dotPos > 3 && spacePos == -1
            && commaPos == -1 && atPos + 1 < dotPos && dotPos + 1 < eMailSize)
        ;
    else {
        alert('E-mail 주소 형식이 잘못되었습니다. /n/r 다시 입력해주세요!');
        document.regFrm.email.focus();
        return;
        // 이메일 형식을 검사하는 부분입니다.
    }
 
    if (document.regFrm.zipcode.value == "") {
        alert("우편번호를 검색해 주세요.");
        return;
    }
 
    if (document.regFrm.job.value == "") {
        alert("직업을 선택해 주세요");
        document.regFrm.job.focus();
        return;
    }
 
    document.regFrm.submit();
}
 
function win_close() {
    self.close();
}
 
cs



zipSearch.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
103
104
105
106
107
108
109
<%@page import="ch14.ZipcodeBean"%>
<%@page import="java.util.Vector"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 
<%
    //우편번호 검색 페이지
    request.setCharacterEncoding("EUC-KR");//얻어온 파라미터값을 출력하기 위해 문자셋 설정
    String check = request.getParameter("search"); //검색결과를 얻어 check변수에 저장
    String area3 = null;
    Vector<ZipcodeBean> vlist = null;
    if (check.equals("y")) //체크한 값이 y(yes)와 같으면
    {
        area3 = request.getParameter("area3");
        vlist = mMgr.zipcodeRead(area3);
    }
%>
<html>
<head>
<title>우편번호 검색</title>
<link href="style.css" rel="stylesheet" type="text/css">
<!-- 디자인을 설정하기 위해 css파일을 불러옴 -->
<script type="text/javascript">
    function loadSearch() //loadSearch()함수는 입력된 도로명 값을 가지고 자신의 페이지 (zipSearch.jsp)를 호출합니다
    {
        frm = document.zipFrm;
        if (frm.area3.value == "")// area3(도로명 쓰는칸)에 아무값도 입력이 되지 않으면
        {
            alert("도로명을 입력하세요.");
            frm.area3.focus();
            return;
        }
        frm.action = "zipSearch.jsp";
        frm.submit();
 
    }
 
    function sendAdd(zipcode, adds) //sendAddress() 함수는 도로명으로 검색된 우편번호와 주소의 값들을 가지고 자신을 오픈 시킨 페이지(member.jsp)로 넘어가면서 창을 닫는 자바스크립트 함수.
    {
        opener.document.regFrm.zipcode.value = zipcode;
        opener.document.regFrm.address.value = adds;
        self.close();
 
    }
</script>
</head>
<body bgcolor="#FFFFCC">
    <div align="center">
        <br />
        <form name="zipFrm" method="post">
            <table>
                <tr>
                    <td><br />도로명 입력 : <input name="area3"> <input
                        type="button" value="검색" onclick="loadSearch();"> <!-- 도로명을 검색할수 있도록 검색 버튼 만듬 -->
                    </td>
                </tr>
                <!-- 검색결과 시작 -->
                <%
                    if (search.equals("y")) {
                        if (vlist.isEmpty()) {
                %>
                <tr>
                    <td align="center"><br />검색된 결과가 없습니다.</td>
                </tr>
 
                <%
                    } else {
                %>
                <tr>
                    <td aling="center"><br />검색 후, 아래 우편번호를 클릭하면 자동으로 입력됩니다.</td>
 
                </tr>
                <%
                    for (int i = 0; i < vlist.size(); i++//for문을 사용해서 우편번호와 주소값을 ZipcodeBean타입으로 반환하고 있다. 
                                                                    //원래Vector의 반환타입은 오브젝트 타입이지만 Vector<ZipcodeBean>타입으로 
                                                                    //제네릭 선언을 해서 변환없이 바로 ZipcodeBean 타입으로 변환한다.
                            {
                                ZipcodeBean bean = vlist.get(i);
                                String rZipcode = bean.getZipcode();
                                String rArea1 = bean.getArea1();
                                String rArea2 = bean.getArea2();
                                String rArea3 = bean.getArea3();
                                String adds = rArea1 + " " + rArea2 + " " + rArea3 + " "//우편번호와 주소값을 adds변수에 저장
                %>
                <tr>
                    <!-- 검색한 결과의 우편번호화 주소를 표현식으로 페이지에 출력하고 출력된 주소값을 자바 스크립트 함수 sendAdd() 함수를 호출하여 우편번호와
        주소를 member.jsp페이지의 우편번호란과 주소란에 자동으로 입력합니다. 입력된 후에는 zipSearch.jsp 페이지가 자동으로 닫힙니다.-->
                    <td><a href='#'
                        onclick="javascript:sendAdd('<%=rZipcode%>', '<%=adds%>')"> <%=rZipcode%>
                            <!-- 자바스크립트 함수의 매개변수의 표현식은 작은 따움표로 묶어야됨 --> <%=adds%></a></td>
                </tr>
                <%
                    } //for
 
                        } //if
 
                    } //if
                %>
                <!-- 검색결과 끝 -->
                <tr>
                    <td align="center"><br /> <a href="#" onClick="self.close()">닫기</a></td>
                </tr>
            </table>
            <input type="hidden" name="search" value="y">
        </form>
    </div>
</body>
</html>
cs



logout.jsp (로그아웃 처리 페이지)

1
2
3
4
5
6
7
8
<%@ page language="java" contentType="text/html; charset=EUC-KR"%>
<%
    session.invalidate();
%>
<script>
    alert('로그아웃 되었습니다.');
    location.href = "login.jsp";
</script>
cs



idCheck.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
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<jsp:useBean id="mMgr" class="ch14.MemberMgr" />
 
<%
    request.setCharacterEncoding("EUC-KR"); //한글이 깨지지 않도록 문자셋 지정
    String id = request.getParameter("id"); //id를 파라미터로 얻어와서 id변수에 넣는다.
    boolean result = mMgr.checkId(id); //아이디가 중복되었는지 체크하는 변수
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ID 중복체크</title>
<link href="style.css" rel="stylesheet" type="text/css">
<!-- 디자인을 설정하기위해 css파일을 불러온다. -->
</head>
<body bgcolor="#FFFFCC">
    <div align="center">
        <br /> <b><%=id%></b>
        <%
            if (result) //result가 참이면 중복된 아이디, 거짓이면 사용할 수 있는 아이디
            {
                out.println("는 이미 존재하는 ID입니다.<p/>");
            } else {
                out.println("는 사용 가능 합니다.<p/>");
            }
        %>
        <a href='#' onClick="self.close()">닫기</a>
        <!-- 현재의 창을 닫는다 -->
 
    </div>
</body>
</html>
cs



ZipcodeBean.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
package ch14;
 
public class ZipcodeBean { // 우편번화 및 주소를 저장하는 자바빈즈
 
    private String zipcode;
    private String area1;
    private String area2;
    private String area3;
 
    public String getZipcode() {
        return zipcode;
    }
 
    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }
 
    public String getArea1() {
        return area1;
    }
 
    public void setArea1(String area1) {
        this.area1 = area1;
    }
 
    public String getArea2() {
        return area2;
    }
 
    public void setArea2(String area2) {
        this.area2 = area2;
    }
 
    public String getArea3() {
        return area3;
    }
 
    public void setArea3(String area3) {
        this.area3 = area3;
    }
 
}
 
cs



MemberBean.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
package ch14;
 
public class MemberBean { // 회원가입의 내용 저장하는 자바빈즈 클래스
 
    private String id;
    private String pwd;
    private String name;
    private String gender;
    private String birthday;
    private String eamil;
    private String zipcode;
    private String address;
    private String hobby[];
    private String job;
 
    public String getId() {
        return id;
    }
 
    public void setId(String id) {
        this.id = id;
    }
 
    public String getPwd() {
        return pwd;
    }
 
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getGender() {
        return gender;
    }
 
    public void setGender(String gender) {
        this.gender = gender;
    }
 
    public String getBirthday() {
        return birthday;
    }
 
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
 
    public String getEamil() {
        return eamil;
    }
 
    public void setEamil(String eamil) {
        this.eamil = eamil;
    }
 
    public String getZipcode() {
        return zipcode;
    }
 
    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }
 
    public String getAddress() {
        return address;
    }
 
    public void setAddress(String address) {
        this.address = address;
    }
 
    public String[] getHobby() {
        return hobby;
    }
 
    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }
 
    public String getJob() {
        return job;
    }
 
    public void setJob(String job) {
        this.job = job;
    }
 
}
 
cs



728x90
반응형
: