본문 바로가기
Develop/Java Server Page

jsp 실습

by jaekk 2018. 6. 26.
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
<!-- loginform.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <h1>실명확인 회원가입</h1>
    <form action="login.jsp" method="post" onsubmit="return check()">
        <table>
            <tr>
                <td><input type="radio" name="methodInfo" value="ipin">아이핀(I-Pin)</td>
                <td><input type="radio" name="methodInfo" value="rrn">주민등록번호</td>
            </tr>
            <tr><td colspan="2">이름 <input type="text" name="name"></td></tr>
            <tr><td colspan="2">주민등록번호 <input type="text" name="rrnFir"> - <input type="password" name="rrnLast"></td></tr>
            <tr><td colspan="2"><input type="checkbox" name="checkBox">주민등록번호 처리에 동의합니다.</td></tr>
            <tr><td colspan="2"><input type="submit" name="btn" value="확인"></td></tr>
        </table>
    </form>
    
<script>
    function check(){
        if(!($('input:radio[name=methodInfo]:checked').val())){
            alert("실명확인 방법을 체크해주세요");
            return false;
        }
        if(!($('input:text[name=name]').val())){
            alert("이름을 입력해주세요");
            $('input:text[name=name]').focus();
            return false;
        }
        if(!($('input:text[name=rrnFir]').val()) || !($('input:password[name=rrnLast]').val())){
            alert("주민등록번호를 입력해주세요");
            $('input:text[name=rrnFir]').focus();
            return false;
        }
        if(!($('input[type=checkbox]').is(":checked"))){
            alert("주민등록번호 처리에 동의 해주세요");
            $('button[name=checkBox]').focus();
            return false;
        } 
 
    }
</script>
</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
<!--  login.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="memberInfo" class="com.member.MemberInfo" />
<jsp:setProperty name="memberInfo" property="*" />
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
 String method = memberInfo.getMethodInfo();
 String methodStr = null;
 String name = memberInfo.getName();
 StringBuffer rrn = new StringBuffer();
 rrn.append(memberInfo.getrrnFir()).append(" - ").append(memberInfo.getrrnLast());
 String regInfo = memberInfo.getCheckBox();
 if(method.equals("ipin")){
     methodStr = "아이핀";
 }else{
     methodStr = "주민등록번호";
 }
%>
    <table>
        <tr><td>가입 방법:</td><td><%=methodStr %></td></tr>
        <tr><td>성명:</td><td><%=name %></td></tr>
        <tr><td>주민등록번호:</td><td><%=rrn %></td></tr>
        <tr><td><input type="button" name="btn" value="회원가입하기"></td></tr>
    </table>
    <script>
        $(document).ready(function(){
            $('input[type=button][name=btn]').click(function(){
                location.href='registerForm.jsp';
            })
        })
    </script>
</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
<!--  registerForm.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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">
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<title>Insert title here</title>
</head>
<body>
    <form action="register.jsp" method="post" onsubmit="return check()">
        <table border="1">
        <tr><td colspan="4">회원가입을 하기에 앞서 회원약관을 읽어 보시기 바랍니다.</td></tr>
        <tr><td colspan="4"><textarea rows="4" cols="50" name="txt">회원약관입니다.</textarea></td></tr>
        <tr><td>이름</td><td colspan="3"><input type="text" name="name"></td></tr>
        <tr><td>아이디</td><td colspan="3"><input type="text" name="id"></td></tr>
        <tr><td>비밀번호</td><td colspan="3"><input type="password" name="pwd" id="pwd"></td></tr>
        <tr><td>비밀번호 재입력</td><td colspan="3"><input type="password" name="pwdRe" id="pwdRe"></td></tr>
        <tr><td>성별</td><td colspan="3">
            <input type="radio" name="gender" value="1" checked>남&nbsp;
            <input type="radio" name="gender" value="2">여
        </td></tr>
        <tr><td>취미</td><td colspan="3">
            <input type="checkbox" name="hobby" value="1">운동
            <input type="checkbox" name="hobby" value="2">음악감상
            <input type="checkbox" name="hobby" value="3">영화감상
            <input type="checkbox" name="hobby" value="4">코딩
        </td></tr>
        <tr><td>직업</td><td colspan="3">
            <select name="job">
                <option value="1">학생</option>        
                <option value="2">회사원</option>        
                <option value="3 ">백수</option>        
            </select>
        </td></tr>
        </table>
        <input type="submit" name="btn" value="확인"></input>
    </form>
    <script>
    $(document).ready(function(){
        $('input[name=btn]').onclick=check;
        $('input[name=pwdRe]').blur(pwdCorr);
    })
        
    function check(){
        if(!($('input:text[name=name]').val())){
            alert("이름을 입력해주세요");
            $('input:text[name=name]').focus();
            return false;
        }
        
        if(!($('input[name=id]').val())){
            alert("아이디를 입력해주세요");
            return false;
        }
        
        if(!($('input:radio[name=gender]:checked').val())){
            alert("성별을 입력해주세요");
            return false;
        } 
    }
    
    // 비밀번호 일치 체크
    function pwdCorr(){
        var pwd = $('input[name=pwd]').val();
        var pwdRe = $('input[name=pwdRe]').val();
        if(pwd != pwdRe){
            alert("비밀번호 불일치입니다.");
            $('input[name=pwd]').val('');
            $('input[name=pwdRe]').val('');
            $('input[name=pwd]').focus();
        }
    } 
          
    </script>
</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
<!-- register.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="memberReg" class="com.member.MemberReg" />
<jsp:setProperty name="memberReg" property="*" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
    String name = memberReg.getName();
    String id = memberReg.getId();
    String gender = (memberReg.getGender() == 1)? "남자" : "여자"
    int[] hobby = memberReg.getHobby();
    String[] hobbyInfo = new String[hobby.length];
    
    for(int i=0;i<hobby.length;i++){
        switch(hobby[i]){
        case 1 : hobbyInfo[i] = "운동";
                break;
        case 2 : hobbyInfo[i] = "음악감상";
                break;
        case 3 : hobbyInfo[i] = "영화감상";
                break;
        case 4 : hobbyInfo[i] = "코딩";
                break;        
        }
    }
    
    String job = (memberReg.getJob() == 1) ? "학생" : (memberReg.getJob() == 2) ? "회사원" : "백수";    
%>
 
 
<table>
    <tr><td>이름</td><td colspan="4"><%=name %></td></tr>
    <tr><td>아이디</td><td colspan="4"><%=id %></td></tr>
    <tr><td>성별</td><td colspan="4"><%=gender %></td></tr>
    <tr><td>취미</td>
    <% for(int i=0;i<hobbyInfo.length;i++){ %>
    <td><%=hobbyInfo[i] %></td<%%>
    <tr><td>직업</td><td><%=job %></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
package com.member;
 
public class MemberInfo {
 
    private String methodInfo;
    private String checkBox;
    private String name;
    private String rrnFir;
    private String rrnLast;
    
    public String getMethodInfo() {
        return methodInfo;
    }
    public void setMethodInfo(String methodInfo) {
        this.methodInfo = methodInfo;
    }
    
    public String getCheckBox() {
        return checkBox;
    }
    
    public void setCheckBox(String checkBox){
        this.checkBox = checkBox;
    }
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getrrnFir() {
        return rrnFir;
    }
    public void setrrnFir(String rrnFir) {
        this.rrnFir = rrnFir;
    }
    public String getrrnLast() {
        return rrnLast;
    }
    public void setrrnLast(String rrnLast) {
        this.rrnLast = rrnLast;
    }
 
}
 
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
package com.member;
 
public class MemberReg {
    private String name;
    private String id;
    private String pwd;
    private int gender;
    private int[] hobby;
    private int job;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    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 int getGender() {
        return gender;
    }
    public void setGender(int gender) {
        this.gender = gender;
    }
    public int[] getHobby() {
        return hobby;
    }
    public void setHobby(int[] hobby) {
        this.hobby = hobby;
    }
    public int getJob() {
        return job;
    }
    public void setJob(int job) {
        this.job = job;
    }
}
 
cs


'Develop > Java Server Page' 카테고리의 다른 글

11. 표현 언어 Expression Language  (0) 2018.07.09
09. 클라이언트와의 대화 1 : 쿠키  (0) 2018.07.06
JSP 정리  (0) 2018.06.24
웹프로그래밍  (0) 2018.06.21
JSP(1)  (0) 2018.06.13

댓글