JQuery 

부트스트랩 - UIFramework

JQueryMoblie UI 버튼 코딩

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
<!-- 모바일 장치에서 웹사이트가 원하는 사이즈로 보여지게 처리 -->
<!-- 
width :  넓이(픽셀) height : 높이(픽셀) 
initial-scale : 초기 배율(기본 꽉 찬 화면)
minimum-scale : 최소 배율(기본 값 : 0.25, 범위: 0~10.0)
maximum-scale : 최대 배율(범위:0~10.0)
user-scalable : 확대, 축소 여부(yes/no)
 -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>화면 상단</h1>
        </div>
        
        <!-- 내용  -->
        <div role="main" class="ui-content">
            <h4>기본 버튼(ui-btn)</h4>
            <a href="#" class="ui-btn">a 태그</a>
            <button class="ui-btn">Button</button>
            
            <h4>모서리가 둥근 버튼(ui-corner-all)</h4>
            <a href="#" class="ui-btn ui-corner-all">a 태그</a>
            <button class="ui-btn ui-corner-all">Button</button>            
            
            <h4>그림자 효과 주기(ui-shadow)</h4>
            <a href="#" class="ui-btn ui-shadow">a 태그</a>
            <button class="ui-btn ui-shadow">Button</button>
            
            <h4>인라인(ui-btn-inline)</h4>
            <a href="#" class="ui-btn ui-btn-inline">a 태그</a>
            <button class="ui-btn ui-btn-inline">Button</button>
            
            <h4>테마(ui-btn-a, ui-btn-b)</h4>
            <a href="#" class="ui-btn ui-btn-b">a 태그</a>
            <button class="ui-btn ui-btn-b">Button</button>
            
            <h4>미니(조금 작게 표시)(ui-mini)</h4>
            <a href="#" class="ui-btn ui-mini">a 태그</a>
            <button class="ui-btn ui-mini">Button</button>
            
            <h4>아이콘 지정(ui-icon-delete), 아이콘 위치(ui-btn-icon-left)</h4>
            <a href="#" class="ui-btn ui-icon-delete ui-btn-icon-left">a 태그</a>
            <button class="ui-btn ui-icon-camera ui-btn-icon-left">Button</button>
            
            <h4>아이콘만 표시(ui-btn-icon-notext)</h4>
            <!-- 직선 테두리를 곡선 형태로 ui-corner-all  -->
            <a href="#" class="ui-btn ui-icon-delete ui-btn-icon-notext ui-corner-all">a 태그</a>
            <button class="ui-btn ui-icon-camera ui-btn-icon-notext">Button</button>
            
            <h4>아이콘 위치 지정(ui-btn-icon-left, right, top, bottom)</h4>
            <!-- 직선 테두리를 곡선 형태로 ui-corner-all  -->
            <a href="#" class="ui-btn ui-icon-delete ui-btn-icon-left">Left</a>
            <a href="#" class="ui-btn ui-icon-delete ui-btn-icon-right">right</a>
            <a href="#" class="ui-btn ui-icon-delete ui-btn-icon-top">top</a>
            <a href="#" class="ui-btn ui-icon-delete ui-btn-icon-bottom">bottom</a>
            
            <h4>비활성화(ui-state-disabled)</h4>
            <a href="#" class="ui-btn ui-state-disabled">a 태그</a>
            <!-- disabled="", disabled="siabled"  둘 다 가능 -->
            <button disabled="disabled">Button</button>
            
            <h4>일반적인 형태의 버튼(data-role="none")</h4>
            <button data-role="none">Button</button>
            
            
                                                            
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
                <h1>화면 하단</h1>
        </div>
    </div>
 
</body>
</html>
cs




커스텀 아이콘

실습 그림파일 

WEBCONTENT - images 폴더 생성후 폴더안에 그림파일 넣음


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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<style type="text/css">
    /* 커스텀 아이어넣는 형식은 정해져 있음  */
    .ui-icon-myicon:after{
        background-image:url("../image/letter-s.png");
        background-size:18px 18px;
    }
</style>
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
 
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>아이콘 그림 지정과 커스텀 아이콘</h1>
        </div>
        
        <!-- 내용  -->
        <div role="main" class="ui-content">
            <h4>아이콘(ui-icon-action)</h4>
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-action">action</button>                        
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-alert">alert</button>
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-arrow-d">arrow-d</button>
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-arrow-d-l">arrow-d-L</button>
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-audio">audio</button>                        
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-camera">camera</button>
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-edit">edit</button>
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-heart">heart</button>
            
            <h4>커스텀 아이콘</h4>
            <!-- .ui-icon-myicon:after{
                background-image:url("../image/letter-s.png");
                background-size:18px 18px;
            } 18px * 18px 그림으로 항상 만들어야한다-->
            <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-myicon">myicon</button>
                        
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
                <h1>화면 하단</h1>
        </div>
    </div>
 
</body>
</html>
cs


Button Group

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
<!-- 모바일 장치에서 웹사이트가 원하는 사이즈로 보여지게 처리 -->
<!-- 
width :  넓이(픽셀) height : 높이(픽셀) 
initial-scale : 초기 배율(기본 꽉 찬 화면)
minimum-scale : 최소 배율(기본 값 : 0.25, 범위: 0~10.0)
maximum-scale : 최대 배율(범위:0~10.0)
user-scalable : 확대, 축소 여부(yes/no)
 -->
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
 
</script>
 
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>Button Group</h1>
        </div>
        
        <!-- 내용  -->
        <div role="main" class="ui-content">
            <h4>수직 버튼 그룹</h4>
            <!-- 
            data-role="controlgroup" 버튼을 수직 또는 수평으로 그룹핑(수직이 기본)
            data-type="horizontal | vertical" 수평, 수직
             -->
            <div data-role="controlgroup">
                <a href="#" class="ui-btn ui-corner-all">No Icon</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-left">Left</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-right">Right</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-top">top</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-bottom">bottom</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-notext">Notext</a>
                
            </div>    
            
            <h4>미니 수직 버튼 그룹</h4>
            <div data-role="controlgroup" data-mini="true">
                <a href="#" class="ui-btn ui-corner-all">No Icon</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-left">Left</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-right">Right</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-top">top</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-bottom">bottom</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-delete ui-btn-icon-notext">Notext</a>
            
            </div>
            
            <h4>수평 버튼 그룹</h4>
            <div data-role="controlgroup" data-type="horizontal">
                <a href="#" class="ui-btn ui-corner-all">No Icon</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-back ui-btn-icon-left">Left</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-forward ui-btn-icon-right">Right</a>            
            </div>
            
            <div data-role="controlgroup" data-type="horizontal">
                <a href="#" class="ui-btn ui-corner-all ui-icon-home ui-btn-icon-top">Top</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-refresh ui-btn-icon-top">Top</a>            
            </div>
            
            <div data-role="controlgroup" data-type="horizontal">
                <a href="#" class="ui-btn ui-corner-all ui-icon-user ui-btn-icon-bottom">bottom</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-shop ui-btn-icon-bottom">bottom</a>            
            </div>            
 
            <div data-role="controlgroup" data-type="horizontal">
                <a href="#" class="ui-btn ui-corner-all ui-icon-phone ui-btn-icon-notext">Icon only</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-mail ui-btn-icon-notext">Icon only</a>            
            </div>    
            
            <h4>미니 사이즈</h4>
            <div data-role="controlgroup" data-type="horizontal" data-mini="true">
                <a href="#" class="ui-btn ui-corner-all ui-icon-user ui-btn-icon-bottom">bottom</a>
                <a href="#" class="ui-btn ui-corner-all ui-icon-shop ui-btn-icon-bottom">bottom</a>            
            </div>                                            
                                                        
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
                <h1>화면 하단</h1>
        </div>
    </div>
 
</body>
</html>
cs


Header와 Footer에 아이콘 적용될때의 차이점

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
<!-- 모바일 장치에서 웹사이트가 원하는 사이즈로 보여지게 처리 -->
<!-- 
width :  넓이(픽셀) height : 높이(픽셀) 
initial-scale : 초기 배율(기본 꽉 찬 화면)
minimum-scale : 최소 배율(기본 값 : 0.25, 범위: 0~10.0)
maximum-scale : 최대 배율(범위:0~10.0)
user-scalable : 확대, 축소 여부(yes/no)
 -->
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
 
</script>
 
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>header</h1>
            <!-- 
                header에서 버튼은 ui-btn을 생략 가능하지만 생략시 기본값 아이콘
                적용되지 않는다. 자동으로 좌우 배치            
            -->
            <a href="#" class="ui-btn ui-btn-icon-left ui-icon-back">이전</a>
            <a href="#" class="ui-btn ui-btn-icon-right ui-icon-forward">다음</a>
            <!-- <a href="#">이전</a>            
            <a href="#" class="ui-btn-icon-right ui-icon-forward">다음</a> -->
        </div>
        <div data-role="header">
            <h1>header</h1>
            <a href="#" class="ui-btn ui-btn-icon-right ui-icon-forward ui-btn-right">다음</a>
        </div>
        
        
        <!-- 내용  -->
        <div role="main" class="ui-content">
                                            
                                                    
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
            <h1>화면 하단</h1>
            <!-- header와 달리 좌우로 자동 배치 되지 않음 임의로 지정 -->
            <!-- 좌우 자동배치가 되지 않기 때문에 좌우를 지정해야 함 -->
            <a href="#" class="ui-btn ui-btn-icon-left ui-icon-back ui-btn-left">이전</a>
            <a href="#" class="ui-btn ui-btn-icon-right ui-icon-forward ui-btn-right">다음</a>
            
        </div>
    </div>
 
</body>
</html>
cs


Header와 Footer 그룹버튼 적용

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
 
</script>
 
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>header</h1>
            <!-- 버튼 그룹에서는 ui-btn 생략 불가 -->
            <div data-role="controlgroup" data-type="horizontal" align="center">
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-delete">Remove</a>
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-plus">Add</a>
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-arrow-u">Up</a>
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-arrow-d">Down</a>
            </div>
        </div>
        
        <!-- 내용  -->
        <div role="main" class="ui-content">
                                                            
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
            <h1>화면 하단</h1>
            <div data-role="controlgroup" data-type="horizontal" align="center">
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-delete">Remove</a>
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-plus">Add</a>
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-arrow-u">Up</a>
                <a href="#" class="ui-btn ui-corner-all ui-btn-icon-left ui-icon-arrow-d">Down</a>
            </div>
        </div>
    </div>
 
</body>
</html>
cs


데이터 입력 및 표시 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
    form {
        width:500px;
        margin:10px auto;
    }
    
    ul {
        padding:0;
        margin:0;
        list-style:none;
    }    
    
    ul li {
        padding:0;
        margin: 0 0 10px 0;
        
    }
    
    label {
        width:100px;
        float:left;            
    }
    
    table {
        border:solid 1px gray;
        width: 500px;
        margin: 0 auto;
        border-collapse:collapse;        
    }
    
    td {
        border: solid 2px gray;
    }
</style>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //목록
        function selectData(){
            //table의 내부내용을 제거(초기화)
            $('#output').empty();
            
            $.getJSON('getPeopleJSON.jsp'function(data){
                $(data).each(function(index,item){
                    var output='';
                    
                    output += '<tr>';
                    output += '<td>'+item.id+'</td>';
                    output += '<td>'+item.name+'</td>';
                    output += '<td>'+item.job+'</td>';
                    output += '<td>'+item.address+'</td>';
                    output += '<td>'+item.bloodType+'</td>';
                    output += '</tr>';
                    
                    $('#output').append(output);
                    
                });
            });
        }
        
        //이벤트 연결 
        $('#insert_form').submit(function(event){
            
            //입력 양식의 내용을 요청 매개 변수 문자열로 만듬
            //(파라미터네임과 value의 쌍, 인코딩 처리)
            var data = $(this).serialize();
            
                    //요청 URL        ,전송할 데이터, 전송이 성공하면 호출되는 함수 
            $.post('insertPerson.jsp', data, initForm); 
            
            //기본 이벤트 제거 
            event.preventDefault();
            
        });
        
        function initForm(data){
                    //전송된 데이터를 JSON 객체로 생성
            var s = $.parseJSON(data); //여기 데이터는 무슨데이터?
            
            if(s.result=='success'){
                alert('등록 완료');
                
                //폼 초기화 
                $('#id').val('');
                $('#name').val('');
                $('#job').val('');
                $('#address').val('');
                $('#bloodType').val('');
            }else {
                alert('등록 실패!!');
            }
            
            //목록 읽기 
            selectData();
            
        }
        
        //초기 회면에 데이터를 표시 
        selectData();
        
    });
</script>
</head>
<body>
<div>
    <form id="insert_form" method="method">
        <fieldset>
            <legend>데이터 추가</legend>
            <ul>
                <li>
                    <label for="id">아이디</label>
                    <input type="text" name="id" id="id">
                </li>
                <li>
                    <label for="name">이름</label>
                    <input type="text" name="name" id="name">
                </li>
                <li>
                    <label for="job">직업</label>
                    <input type="text" name="job" id="job">
                </li>                                
                <li>
                    <label for="address">주소</label>
                    <input type="text" name="address" id="address">
                </li>                            
                <li>
                    <label for="id">혈행형</label>
                    <input type="text" name="bloodType" id="bloodType">
                </li>
                <li>
                    <input type="submit" value="추가">
                </li>
            </ul>
        </fieldset>                
    </form>
</div>
 
<table id="output">
    
</table>
 
</body>
</html>
cs


get People JSON.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
<%@ page language="java" contentType="text/plain; charset=euc-kr"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
[<% 
String jdbcUrl = "jdbc:oracle:thin:@172.18.65.193:1521:xe";
String dbId = "hr";
String dbPass = "hr";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
 
try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(jdbcUrl, dbId, dbPass);
    
    String sql = "select * from people order by id asc";
    pstmt = conn.prepareStatement(sql);
    rs = pstmt.executeQuery();
    
    while(rs.next()){
        String id = rs.getString("id");
        String name = rs.getString("name");
        String job= rs.getString("job");
        String address= rs.getString("address");
        String bloodType= rs.getString("bloodType");
        
        if(rs.getRow()>1){
            out.print(", ");
        }
        %>
        {
            "id": "<%=id %>",
            "name": "<%=name %>",
            "job": "<%=job %>",
            "address": "<%=address %>",
            "bloodType": "<%=bloodType %>"            
        }
        <%
    }    
    
}catch(Exception e){
    e.printStackTrace();
    
} finally{
    if(rs!=null)try{rs.close();}catch(SQLException e){}
    if(pstmt!=null)try{pstmt.close();}catch(SQLException e){}
    if(conn!=null)try{conn.close();}catch(SQLException e){}
}
    
%>
]
cs

insertPerson.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
<%@ page language="java" contentType="text/plain; charset=euc-kr"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<% 
String jdbcUrl = "jdbc:oracle:thin:@172.18.65.193:1521:xe";
String dbId = "hr";
String dbPass = "hr";
 
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String job = request.getParameter("job");
String name = request.getParameter("name");
String address = request.getParameter("address");
String bloodType = request.getParameter("bloodType");
Connection conn = null;
PreparedStatement pstmt = null;
 
try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(jdbcUrl, dbId, dbPass);
    
    String sql = "insert into people(id, name, job, address, bloodType) values (?,?,?,?,?)";
    pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, id);
    pstmt.setString(2, job);
    pstmt.setString(3, name);
    pstmt.setString(4, address);
    pstmt.setString(5, bloodType);
    
    pstmt.executeUpdate();
    %>
    {"result":"success"}
    <%
    
}catch(Exception e){
    
    %>
    {"result":"failure"}
    <%
    e.printStackTrace();
    
} finally{
    
    if(pstmt!=null)try{pstmt.close();}catch(SQLException e){}
    if(conn!=null)try{conn.close();}catch(SQLException e){}
}
    
%>
 
cs




JQueryMobile + SenchaTouch

교재: 

jQueryMobilenSenchaTouch.pdf


데이터 처리량이 많지 않은 곳에서 사용

앱을 만든다면 아직까지는 네이티브를 추천 

속도를 향상시키기이해서는 웹브라우저 자체 엔진의 속도를 향상시켜야 한다 


기초

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
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
<!-- 모바일 장치에서 웹사이트가 원하는 사이즈로 보여지게 처리 -->
<!-- 
width :  넓이(픽셀) height : 높이(픽셀) 
initial-scale : 초기 배율(기본 꽉 찬 화면)
minimum-scale : 최소 배율(기본 값 : 0.25, 범위: 0~10.0)
maximum-scale : 최대 배율(범위:0~10.0)
user-scalable : 확대, 축소 여부(yes/no)
 -->
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
 
</script>
 
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>화면 상단</h1>
        </div>
        
        <!-- 내용  -->
        <div role="main" class="ui-contnet">
            <p>Hello jQuery Mobile</p>
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
                <h1>화면 하단</h1>
        </div>
    </div>
 
</body>
</html>
cs


JQUERY + 버튼 만들기 

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Mobile</title>
<!-- 모바일 장치에서 웹사이트가 원하는 사이즈로 보여지게 처리 -->
<!-- 
width :  넓이(픽셀) height : 높이(픽셀) 
initial-scale : 초기 배율(기본 꽉 찬 화면)
minimum-scale : 최소 배율(기본 값 : 0.25, 범위: 0~10.0)
maximum-scale : 최대 배율(범위:0~10.0)
user-scalable : 확대, 축소 여부(yes/no)
 -->
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../mobile/jquery.mobile-1.4.5.min.css">
<script type="text/javascript" src="../mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
 
</script>
 
</head>
 
<body>
    <!-- page 지정 -->
    <div data-role="page">
        <!-- header  -->
        <div data-role="header">
            <h1>화면 상단</h1>
        </div>
        
        <!-- 내용  -->
        <div role="main" class="ui-content">
            <h4>기본 버튼(ui-btn)</h4>
            <a href="#" class="ui-btn">a 태그</a>
            <button class="ui-btn">Button</button>
            
            <h4>모서리가 둥근 버튼(ui-corner-all)</h4>
            <a href="#" class="ui-btn ui-corner-all">a 태그</a>
            <button class="ui-btn ui-corner-all">Button</button>            
            
            <h4>그림자 효과 주기(ui-shadow)</h4>
            <a href="#" class="ui-btn ui-shadow">a 태그</a>
            <button class="ui-btn ui-shadow">Button</button>
            
            <h4>인라인(ui-btn-inline)</h4>
            <a href="#" class="ui-btn ui-btn-inline">a 태그</a>
            <button class="ui-btn ui-btn-inline">Button</button>
            
            <h4>테마(ui-btn-a, ui-btn-b)</h4>
            <a href="#" class="ui-btn ui-btn-b">a 태그</a>
            <button class="ui-btn ui-btn-b">Button</button>
                        
        </div>
        
        <!-- footer  -->
        <div data-role="footer">
                <h1>화면 하단</h1>
        </div>
    </div>
 
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>기본 이벤트 제거</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<style>
    * {
        margin:5px;
        padding:5px;
        border:3px solid black;
    }
</style>
<script type="text/javascript">
    $(function(){
        $('a').click(function(event){
            $(this).css('background-color''blue');
            
            //기본 이벤트 제거
            //return false; 써도 됨
            event.preventDefault();
        });
    });
</script>
</head>
<body>
    <h1>
        <a href="http://www.naver.com">네이버</a>
    </h1>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>이벤트 전파 제거</title>
<style>
    * {
        margin:5px;
        padding:5px;
        border:3px solid black;
    }
</style>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        $('h1').click(function(){
            $('h1').click(function(){
                $(this).css('background-color''yellow');
            });
            
            $('p').click(function(){
                $(this).css('background-color''pink');
                
                //이벤트 전파제거
                event.stopPropagation();
            });
        });
    });
</script>
</head>
 
<body>
<h1 id="header">header
    <p id="paragraph">Paragraph</p>
</h1>
 
</body>
</html>
cs

이벤트 제거 처리를 안하면 Paragraph 를 클릭해도 Header부분의 색깔이 변경

이벤트 제거 처리후 Pragraph 영역의 색깔만 변한다 

        


동적으로 만드는 태그를 통해 연결이 필요시 on method를 사용한다

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>미래에 만들어질 태그에 이벤트 연결</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //현재의 태그와 미래의 태그 모두 이벤트 연결
        $(document).on('click''h1'function(){
            var length = $('h1').length//h1태그의 갯수 
            var targetHTML = $(this).html();
            //기존 데이터 뒤에 새로 만들어진 데이터를 삽입
            $('#wrap').append('<h1>'+length' - ' + targetHTML+ '</h1>');            
        });
    });
    
</script>
</head>
<body>
    <div id="wrap">
        <h1>Header</h1>
    </div>
</body>
</html>
cs




AJAX

굉장히 빠르다는 느낌으로 페이지를 부분적으로 처리 가능 

구글이 전폭적으로 AJAX 를 활용한 후 전세계에 활성화

비동기 통신과 전체적인 페이지를 다시 로딩해야 하는 경우를 구분하여 페이지 작성

데이터를 받는 페이지 

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
//AJAX(Asynchronous Javascript And XML) : 자바스크립트와 XML을 이용한 비동기 통신
 $(function(){
    //text 정보 일기
    //         URL                      옵션
    $.ajax('myFirstStringAction.jsp', {
        //통신이 성공해서 서버에서 데이터 전송된 경우
        success:function(data){
            //data : 서버에서 전송된 데이터
            //body에 전송된 데이터를 추가
            $('body').append(data);
        }
    });            
 });
</script>
</head>
<body>
 
</body>
</html>
cs

데이터 받아올 서버 myFirstStringAction.jsp

1
2
3
<%@ page language="java" contentType="text/plain; charset=UTF-8"
    pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
Hello JSP!!    
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //데이터를 서버로 전송한 후 서버에서 데이터 전달 받기
        $.ajax({
            //호출 URL
            url:'myFirstParamAction.jsp'// 요청 URL
            data: {name'dragon', age:21}, //서버쪽에 전달할 데이터
            success: function(data){ // 서버의 응답이 성공 했을때 호출
                $('body').append(data);
            }
        });
    });
</script>
</head>
<body>
    
</body>
</html>
cs

myFirstParamAction.jsp

1
2
3
4
5
6
7
8
9
<%@ page language="java" contentType="text/plain; charset=UTF-8"
    pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%
    String name = request.getParameter("name");
    String age = request.getParameter("age");
        
%>
이름 : <%name%>, 나이 : <%age %>
 
cs


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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //XML 데이터를 읽어 옴
        $.ajax('myFirstXMLAction.jsp',{
            success:function(data){
                $(data).find('person').each(function(){
                    //find 메소드를 이용해서 태그에 접근
                    var name = '<li>' + $(this).find('name').text() + '</li>';
                    var job = '<li>' + $(this).find('job').text() + '</li>';
                    var age = '<li>' + $(this).find('age').text() + '</li>';
                    
                    $('body').append('<ul>' + name + job + age + '</ul>');                    
                }); // 각각의 배열을 접근하여 person 을 찾음
            }
        });
    });
</script>
</head>
<body>
 
</body>
</html>
 
cs

서버 - myFirstXMLAction.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<%@ page language="java" contentType="text/xml; charset=UTF-8"
    pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<?xml version="1.0" encoding="UTF-8"?>
<people>
    <person>
        <name>강호동</name>
        <job>MC</job>
        <age>45</age>
    </person>
    <person>
        <name>유재석</name>
        <job>MC</job>
        <age>44</age>
    </person>    
</people>    
cs

JSON 을 활용해 데이터 받기

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
//JSON: Java Script Object Notation
//XML에 비해 용량이 반으로 줄어들어 더 빠르게 데이터 전송 가능 
//JSON은 JSON 전용 데이터 메소드가 있어 바로 처리 가능
    $(function(){
        $.getJSON('myFirstJSONAction.jsp'function(data){
            $(data).each(function(index, item){
                var output = '';
                output += '<div>';
                output += '<h1>'+ item.name+'</h1>';
                output += '<p>'+ item.job+'</p>';
                output += '<p>'+ item.age+'</p>';
                output += '</div>';
                
                $('#output').append(output);
                
            });
        });
    });
 
</script>
</head>
<body>
    <div id="output"></div>
</body>
</html>
 
cs

데이터 서버 페이지 - myFirstJSONAction.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<%@ page language="java" contentType="text/plain; charset=UTF-8"
    pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
 
[
    {
        "name": "강호동",
        "job": "MC",
        "age": 30
    },    
    {
        "name": "유재석",
        "job": "MC",
        "age": 50        
    }
]
 
cs



데이터베이스에서 데이터 가져오기

JDBC 드라이버 파일을 다운받아 WEB-INF -> lib 폴더에 넣는다

ojdbc14.jar


교재 PDF

jQuery.pdf


jQuery 의 특징

DOM과 관련된 처리를 쉽게 구현

CSS 선택자를 이용하여 쉽고 편리하게 요소를 선택

일괄된 이벤트 연결을 쉽게 구현

시각적 효과를 쉽게 구현

Ajax 애플리케이션을 쉽게 개발

일반인들이 만든 플러그인을 이용할수 있음

jquey-1.11.2.js

jquery-1.11.2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery 연결</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    //window.onload = function(){};
    //문서가 준비 완료되면 매개변수로 전달된 함수를 실행하라는 의미
    
    $(document).ready(function(){
        alert('First Ready');
    });
    
    $(document).ready(function(){
        alert('Second Ready');
    });
    
    $(document).ready(function(){
        alert('Third Ready');
    });
</script>
</head>
<body>
 
</body>
</html>
cs



jQuery 연결

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery 연결</title>
<!-- CDN : Contents Delivery Network  -->
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<!-- <script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script> -->
<script type="text/javascript">
    //HTML 페이지에 있는 모든 문서 객체를 선택하는 선택자
    $(document).ready(function(){
        
        $('*').css('color''red'); //* 전체 선택자
 
    });
</script>
</head>
<body>
    <h1>장마</h1><br>
    <h2>여름</h2>
</body>
</html>
cs


id선택자, 클래스 선택자, 태그 선택자

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>id선택자, 클래스 선택자, 태그 선택자</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    //$(document).ready(function(){});
    $(function(){
        //태그 선택자    속성     속성값
        $('span').css('border''3px solid blue');
        
        //클래스 선택자
        $('.my').css('border''5px solid red');
        
        //id 선택자
        $('#content').css('background''green');
    });
</script>
</head>
<body>
    <p class="my">jQuery 실습</p>
    <div>
        <div id="content">id값이 content인 div 태그</div>
    </div>
    <span>span1</span>
    <span class="my">span2</span>
</body>
</html>
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>id선택자, 클래스 선택자, 태그 선택자</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //여러개의 태그 선택
        $('h1,p').css('color''orange');
    });
</script>
</head>
<body>
    <h1>강물</h1>
    <p>파도</p>
    <h1>새벽</h1>
    <div>별</div>
    
</body>
</html>
cs


05.html - 특정 id 속성을 가지는 태그 선태 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>id선택자, 클래스 선택자, 태그 선택자</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //특정 id 속성을 가지는 태그 선택
        $('h1#target').css('color''orange');
    });
</script>
</head>
<body>
    <h1>header-0</h1>
    <h1 id="target">header-1</h1>
    <h1>header-2</h1>
</body>
</html>
 
cs


06.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>id선택자, 클래스 선택자, 태그 선택자</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //특정 id 속성을 가지는 태그 선택
        $('h1#target').css('color''orange');
    });
</script>
</head>
<body>
    <h1>header-0</h1>
    <h1 id="target">header-1</h1>
    <h1>header-2</h1>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>자신 선택자</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function() {
        //자식 선택자
        //body 태그의 자식(직계자신)
        $('body > div').css('border''3px solid red');
    });
</script>
</head>
<body>
    <div>
        <div>
            <ul>
                <li>사과</li>
                <li>바나나</li>
                <li>망고</li>
                <li>오렌지</li>
            </ul>
            <div>가을 여행</div>
        </div>
    </div>
    <p>
        <span>하하</span>
    </p>
    
</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
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>후손 선택자</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function() {
        //후손 선택자
        //body 이하 div 선택(후손 중 div 선택)
        $('body div').css('border''3px solid red');
    });
</script>
</head>
<body>
    <div>
        <div>
            <ul>
                <li>사과</li>
                <li>바나나</li>
                <li>망고</li>
                <li>오렌지</li>
            </ul>
            <div>가을 여행</div>
        </div>
    </div>
    <p>
        <span>하하</span>
    </p>
 
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배열</title>
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //배열 선언 
        var array = [
                     {name'naver', link:'http://www.naver.com'},
                     {name'daum', link:'http://www.daum.net'},
                     {name'nate', link:'http://www.nate.com'},
                     {name'google', link:'http://www.google.co.kr'}
                     ];
        
            // 배열     배열로부터 데이터를 받아서 처리하는 함수
        $.each(array, function(index, item){
            //index : 배열의 index
            //item : 배열의 인덱스를 통해 접근한 객체(key:value)
            
            var output='';
            output+='<a href='+item.link + '>';
            output+='<h1>'+item.name+'</h1>';
            output+='</a>';
            
            document.body.innerHTML += output;
        });
    });
</script>
</head>
<body>
 
</body>
</html>
cs








<div>

<h1>하늘<h1>

</div>

append 기능 을 이용하면 하늘 다음에 데이터가 들어간다 

HTML은 누적해서 데이터를 보여주지 못하므로 append 가능을 이용해서 데이터 표시

하이브리드 특강 2일차 오전: 자바스크립트

웹에서 가져온 데이터를 뿌려줄때 자바스크립트를 이용해 DOM을 제어함

생성자를 이용한 객체 생성


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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>생성자 함수를 이용한 객체 생성</title>
<script type="text/javascript">
// 생성자 함수 지정
function Student(name, korean, math, english, science) {
this.이름 = name;
this.국어 = korean;
this.영어 = english;
this.수학 = math;
this.과학 = science;
 
// 메서드
this.getSum = function(){
return this.국어 + this.수학+ this.영어 + this.과학
};
this.getAverage = function(){
return this.getSum() / 4;
};
this.toString = function(){
return this.이름 + ', ' + this.getSum() + ',' + this.getAverage();
};
}
 
// 생성자 함수를 이용한 객체 생성
var student = new Student('홍길동'100909897);
document.write(student.toString());
</script>
</head>
<body>
</body>
</html>
cs

라이브러리를 만들어서 이용할떄 위와 같이 사용 

위와 같은 형태로 자바스크립트 상속도 가능(이번 수업에서는 배우지 않는다)

애플릿 -> 플래쉬 -> 자바스크립트

DOM 객체 트리 생성

출력

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM</title>
<script type="text/javascript">
window.onload = function() {
//변수 선언
var output = '';
output += '<ul>';
output += ' <li>JavaScript</li>';
output += ' <li>JQuery</li>';
output += ' <li>Ajax</li>';
output += '</ul>'
 
//innerHTML 속성에 문자열을 할당
document.body.innerHTML = output;
};
</script>
</head>
<body>
 
</body>
</html>
cs

요소선택 

window.onload : HTML 문서가 완전히 업로드 된후 자바 스크립트 실행

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM</title>
<script type="text/javascript">
window.onload = function () {
var spans = document.getElementsByTagName('span');
spans[0].innerHTML = '호수';
spans[1].innerHTML = '들판';
 
};
</script>
</head>
<body>
    <span>하늘</span>
    <span>하늘</span>
    
</body>
</html>
cs

For 문 이용해서 요소 선택후 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM</title>
<script type="text/javascript">
window.onload = function () {
var spans = document.getElementsByTagName('span');
 
for (var i = 0; i<spans.length; i++){
if(i%2==1){
spans[i].innerHTML = '우주';
else {
spans[i].innerHTML = '지하';
}
}
};
</script>
</head>
<body>
    <span>하늘</span>
    <span>하늘</span>
    <span>하늘</span>    
</body>
</html>
cs

ID를 이용한 접근

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM</title>
<script type="text/javascript">
window.onloadfunction(){
//문서 객체를 가져옴
var header1 = document.getElementById('header_1');
var header2 = document.getElementById('header_2');
 
header1.innerHTML = '하하';
header2.innerHTML = '호호';
};
</script>
</head>
<body>
    <h1 id="header_1">Header</h1>
    <h1 id="header_2">Header</h1>
</body>
</html>


태그에 접근하는 많은 방법중 가장 빈번한 방법은 태그와 아이디 

Event - inline 이벤트 처리

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>event - 인라인 이벤트 처리</title>
</head>
<body>    
    <input type="button" value="이동" onclick="location.href='http://www.naver.com'">
    
    <!-- 한라인에 여러 이벤트 삽입 끝을 제외하고는 ; 삽입  -->
    <input type="button" value="확인" onclick="alert('클릭');alert('클릭')">    
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>event - script에서 이벤트 처리</title>
<script type="text/javascript">
window.onload = function(){
var header = document.getElementById('header');
 
//이벤트가 발생할 때 호출되는 함수 
function whenClick(){
alert('Click');
}
 
//이벤트 연결 
header.onclick = whenClick;
};
</script>
</head>
<body>
    <div id="header">클릭</div>    
</body>
</html>
cs

다른 이벤트 연결 처리 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>event - script에서 이벤트 처리</title>
<script type="text/javascript">
window.onload = function(){
var header = document.getElementById('header'); 
 
//이벤트 연결 
header.onclick = function whenClick(){
alert('클릭');
}
};
</script>
</head>
<body>
    <div id="header">클릭</div>    
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>기본 이벤트</title>
<script type="text/javascript">
    window.onload = function(){
        var aa = document.getElementById('aa');
        //이벤트 연결 
        aa.onclick=function(){
            alert('이벤트 연결');
            
            //기본 이벤트 제거 
            return false;
        };
        
        var myForm = document.getElementById('myForm');
        
        //이벤트 연결
        myForm.onsubmit = function(){
            alert('이벤트 연결');
            
            // 기본 이벤트 제거
            return false;
        };
    };
</script>
</head>
<body>
    <a id="aa" href="http://www.naver.com">이동</a>    
    <br><br>
    <form id="myForm" action="a.jsp" method="get">
        <input type="text" name="name"><br>
        <input type="submit" value="전송">
        
    </form>
</body>
</html>



이벤트 버블링 (모든 브라우저에서 지원하므로 표준)

자시쪽에서 부모쪽으로 이벤트 전파 

이벤트 캡쳐링(IE는 지원하지 않는다)

부모쪽에서 자식쪽으로 이벤트 전파 

전달 막는것 예제

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
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>이벤트 전파</title>
<script type="text/javascript">
    window.onload = function(){
        //문서 객체에 접근
        
        var header = document.getElementById('header');
        header.onclick = function(){
            alert('header');
            //this : 이벤트가 발생한 객체
            this.style.background='pink';            
        };
        
        var paragraph = document.getElementById('paragraph');
        paragraph.onclick = function(e){
            alert('paragraph');
            this.style.background='yellow';
            /*
                인터넷 익스플로러 8이하의 버전은 이벤트가 발생할 때 이벤트 객체를
                window.event 속성으로 전달하지만, 다른 브라우저는 핸들러의 
                매개 변수로 전달
                인터넷 익스플로러 9이상에서는 매개변수, window.event 둘 다 지원                
            */
            
            var event = e || window.event;
            
            //이벤트 전달을 제거            
            event.cancelBubble = true;
            if(event.stopPropagation){
                event.stopPropagation()
            }            
                        
        };
    };
</script>
</head>
<body>
    <h1 id="header">header
        <p id="paragraph">Paragraph</p>
    </h1>
    
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>지역변수와 전역변수</title>
<script type="text/javascript">
/* 
1. 지역변수 
함수 안에서 var를 사용해서 선언한 변수, 함수가 끝나면 소열 
2. 전역변수
함수밖에서 만들어진 모둔 변수
함수안에서 var없이 만들어진 변수
함수가 끝나도메ㅗ
*/
 
function test1(){
var i = 10// 지역변수 
document.write(i);
}
test1();
 
//document.write(i);
 
//지역변수는 함수가 끝나면 소멸
//document.write(i);
 
var j; //전역변수
function test2(){
j = 200;
document.write('<br>'+j);
}
test2();
document.write('<br>'+j);
 
//전역변수
//a;//var를 명시하지 않고 전역변수를 만들면 선언과 함께 초기해야함
a = 10;
 
function test3(){
a = 100;
document.write('<br>'+a);
}
test3();
 
//함수 내에서 var를 명시하지 않고 변수를 선언하면 전역변수
function test4(){
m = 300// 전역변수
document.write('<br>'+m);
}
test4();
document.write('<br>'+m);
 
 
</script>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>함수를 매개 변수로 받는 함수</title>
<script type="text/javascript">
//함수를 10번 호출하는 함수
function callfunctionTenTime(otherFunction){ //otherFunction 이 함수명을 대신
for(var i = 0; i<10; i++){
otherFunction();
}
}
 
//선언적 함수
function justFunction(){
document.write('Happy Day!<br>');
 
}
 
//함수로 전달할때() 적지 않는 것 주의
callfunctionTenTime(justFunction);
document.write("===============<br>");
 
//익명 함수 전달
callfunctionTenTime(function(){
document.write('Hello JavaScript<br>');
});
 
 
</script>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>내부 함수</title>
</head>
<script type="text/javascript">
 
function f(){
//내부 함수
function g(){
document.write('g is called');
}
g();
}
//함수 호출
f();
</script>
<body>
    
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>내부 함수</title>
<script type="text/javascript">
function f(){
var n = 123//지역변수
function g(){
document.write('n is '+n+'<br>');
document.write('g is called');
}
g();
}
f();
</script>
</head>
<body>
 
</body>
</html>
cs

예제3 (클로저 사용)

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>내부 함수</title>
<script type="text/javascript">
/* 
지역변수는 함수가 실행될 때 생성되고 함수가 종료될 때 사라진다.
하지만, 클로저를 사용하면 이 규칙을 위반 할 수 있다.
지역변수를 남겨두는 현상을 클로저라고 부름 
*/
 
function f(){
var n = 123;
function g(){
document.write('n is'+n+'<br>');
document.write('g is called');
return g;
}
//함수 호출 
var n = f();
document.write(n + '<br>');
document.write('====================<br>');
n();
</script>
</head>    
<body>
    
</body>
</html>
cs

- 클로저의사용 

함수안에있는변수는지역 변수이므로외부에서사용할수 없음. 클로저를사용하면 이규칙을 위반하여지역변수를사용할수 있도록할수 있음. 

익명함수를반환하는함수에지역변수가있으면익명함수는클로저함수로서지역변수를가져다 쓸수 있음. 

클로저란? 

- 지역 변수를남겨두는현상 

- 함수outerFunction()로 인해생성된공간 

- 함수outerFunction() 내부의변수들이살아있음 

- 리턴되는함수자체 

- 살아남은지역 변수


배열 

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배열</title>
<script type="text/javascript">
var array = ['포도''사과''바나나''망고'];
document.write(array[0]+'<br>');
document.write(array[1]+'<br>');
document.write(array[2]+'<br>');
document.write(array[3]+'<br>');
 
// 반복문을 이용한 출력
var output='';
/*  for(var i=0; i<array.length;i++){
output += i+ ' : ' + array[i] + '\n';
} */
 
// for in 반복문을 이용한 출력
for (var i in array){
output += i+ ' : ' + array[i] + '\n';
}
alert(output);
</script>
</head>
<body>
    
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배열</title>
<script type="text/javascript">
var array=['포도''사과'];
document.write(array+'<br>');
 
array[2] = '사과';
document.write(array+'<br>');
 
array[10] = '망고';
document.write(array+'<br>');
/*  출력
포도,사과
포도,사과,사과
포도,사과,사과,,,,,,,,망고
*/
 
document.write(array[4]+'<br>'); /* 출력: undefined  */
document.write('============================<br>');
 
var array2 = ['one''two''three'];
array2.length = 2// 마지막 데이터 제거
document.write(array2+'<br>');
 
array2.length = 4;
document.write(array2+'<br>');
</script>
</head>
<body>
    
</body>
</html>
cs

배열 예제 3

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배열</title>
<script type="text/javascript">
//비어 있는 배열 생성
var array1 = new Array();
 
document.write(array1+'<br>');
document.write(array1.length+'<br>');
 
//데이터를 저장할 수 있는 10개의 공간을 생성
var array2 = new Array(10);
document.write(array2+'<br>');
document.write(array2.length+'<br>');
 
//저장된 데이터를 전달해서 배열 생성
var array3 = new Array(522731035732);
document.write(array3+'<br>');
document.write(array3.length+'<br>');
 
</script>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>객체</title>
<script type="text/javascript">
var product = {
//속성(Key(프로퍼티):value)
제품명:'갤럭시노트4',
제품번호:'A1001',
기능:'멀티윈도우',
원산지:'대한민국',
가격:1000
업데이트지원:true
};
 
document.write(product.제품명+'<br>');
document.write(product.제품번호+'<br>');
document.write(product['기능']+'<br>');
document.write(product['원산지']+'<br>');
document.write(product['가격']+'<br>');
document.write(product['업데이트지원']+'<br>');
</script>
</head>
<body>
 
</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
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>객체</title>
<script type="text/javascript">
 
var name = '이순신';
 
var person = {
 
//속성 지정
name:'홍길동',
//메서드 지정
eat:function(food){
var name = '김유신';
//this:메서드 내에서 객체자신이 가지고 있는 속성을 호출하고 할 떄 
//객체 내부에서 객체를 참조할 때 사용
//지역변수를 찾고 없을 경우는 객체 밖에 선언된 전역번수를 찾음 
alert(this.name+'이 '+food+'을 먹습니다.');
//alert(name+'이 '+food+'을 먹습니다.');
 
}
};
//메서드 호출
person.eat('밥, 반찬');
</script>
</head>
<body>
    
</body>
</html>
cs

객체 예제 3

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>객체</title>
<script type="text/javascript">
var student = {};
 
 
//객체에 속성 추가
student.이름 = '홍길동';
student.취미 = '악기';
student.특기 = '프로그래밍';
student.장래희망 = '프로그래머';
 
document.write(student.이름+'<br>');
document.write(student.특기+'<br>');
document.write(student.취미+'<br>');
//반복문을 이용한 출력
var output = '';
for(var key in student){
output += key + ':' + student[key] + '<br>';
}
document.write(output);
document.write('---------------<br>');
 
//객체에 메서드 추가
student.toString = function() {
var msg='';
for(var key in this){//this: 자기자신
if(key!='toString'){
msg += key + ':'+ this[key]+'<br>';
}
}
return msg;
};
document.write(student.toString()); 
 
</script>
</head>
<body>
 
</body>
</html>
 
cs



하이브리드 프로그래밍의 기본 기반은 HTML5

HTML5는 정적인 언어이기때문에

JAVASCRIPT 가 동적인 부분을 담당

수업 개요d


제3차 실무프로그래밍 강좌 강의계획서.pdf


JAVASCRIPT

JQUERY 

설치

Oracle.com -> JavaSE sdk 7버전 다운로드

강사님이 주신 Eclipse 사용

Ext JS - 데스크탑 환겨에서 사용

데이터 처리하면서 디자인적인면 두곳이 혼합되어 있음 

단점: 느려서 국내에서 사용하지 않았음

센차 터치 - 모바일에서 주로 사용

백엔드 스프링

웹 구현시 - 보통 하던데로 데이터를 받아와서 구현하면 된다.

모바일 구현시 - JSON 혹은 XML 로 데이터르 받아와 센차 터치에서 구현


사물인터넷의 시대를 준비하라


자바스크립트 기초 강의 자료

Javascript.pdf


이클립스 다운로드

톰캣 세팅

Dynamic Web Project 생성

Window -> Browser -> Default System Browser



JavaScript 객체 학습은 필요함 -> Professional JavaScript for Web Development


--------------------------------

자바스크립트 body와 head에서의 실행순서가 다르다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>실행 위치</title>
<script type="text/javascript">
document.write('head에서 살행<br>');
</script>
</head>
<body>
<script type="text/javascript">
document.write('body에서 실행');
</script>
</html>
 
cs

- 자바스크립트를외부파일로사용 

<script type="text/javascript" src="자바스크립트파일명.js"></script> 

- HTML 태그에인라인(inline) 형태로삽입해서사용 

<input type=”button” value=”이동” onclick=”location.href=’index.html’”> 

자바 스크립트 출력

document.write('자바스크립트출력구문'); 

자바스크립트주석 

 //  : 한줄주석처리 

 /* ~ */ : 한줄이상의주석처리 

**자바스크립트와 다른 언어와 다른점: 함수를 자료형으로 취급


변수
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>변수</title>
<script type="text/javascript">
//변수 선언
var num;
 
//변수에 값을 할당
num = 123;
 
//출력
document.write('num = ' + num);
document.write('<br>');
 
//변수 선언과 초기화를 한 번에 함
var c = 10, d = 3.5;
// bracket 을 해주지 않으면 문자열로 변환되서 계산되지 않음
document.write('c+d='+(c+d)));
</script>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>자료형</title>
<script type="text/javascript">
//변수를 선언
var stringVar = 'String'//문자열
var numberVar = 273//숫자
var booleanVar = true//boolean
var functionVar = function(){} // 함수
var objectVar = {};
 
//typeof 변수명: 해당 변수에 저장된 데이터의 타입을 알아내는 연산자
document.write('stringVar : '+typeof stringVar + '<br>');
document.write('numberVar : '+typeof numberVar + '<br>');
document.write('booleanVar : '+typeof booleanVar + '<br>');
document.write('functionVar : '+typeof functionVar + '<br>');
document.write('objectVar : '+typeof objectVar + '<br>');
 
 
</script>
</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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>자료형과 형변환</title>
<script type="text/javascript">
var input = prompt('숫자를 입력하세요''숫자');
 
document.write(typeof(input)+':'+input);
document.write('<br>');
 
document.write(input*10); // 자동적으로 형변환 
document.write('<br>');
document.write(input+10);
 
//형변환
//문자(문자열)를 숫자로 변환
var numberInput = Number(input); // 문자->숫자
document.write('<br>형변환 이후 <br>');
document.write(typeof(numberInput)+':'+numberInput);
document.write('<br>');
document.write(numberInput+10);
 
</script>
</head>
<body>
    
</body>
</html>
cs

나머지 연산자 기능은 기존 프로그래밍 언어 문법들과 비슷

** 주의해야할 비교 연산자

 ==            a == b              a 와b 의값이같은지비교 

 !=            a != b              a 와b 의값이 다른지비교 

 ===           a === b             a 와b 의값뿐만아니라자료형도같은지비교 

 !==           a!==b               a 와b 의값뿐만아니라자료형도 다른지비교 

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>비교연산자</title>
<script type="text/javascript">
/* 
연산자 설명
=== 양 변의 자료형과 값이 일치해야 true
!== 양 번의 자료형과 값이 다르면 false
*/
var a = 20, b = '20', c;
 
c = a == b;
document.write('a == b : ' + c + '<br>'); // 자동 형변환이 이루어져서 true
 
c = a != b;
document.write('a != b : ' + c + '<br>'); 
 
c = a === b;
document.write('a === b : ' + c + '<br>');
 
c = a !== b;
document.write('a !== b : ' + c + '<br>');
 
</script>
</head>
<body>
</body>
</html>
cs


+ Recent posts