자바스크립트의 선언


자바스크립트는 선언문을 기준으로 시작한다.


1
2
3
<script>
    자바스크립트 코드
</script>
cs


head나 body태그 안에 선언이 가능하다. 하지만 대부분 head태그 안에 선언한다.


1
2
3
4
5
6
7
<head>
    <meta charset="EUC-KR">
    <title>선언문</title>
    <script>
        document.write("환영합니다");
    </script>
</head>
cs


자바스크립트의 주석은 한 줄 주석의 경우 '//'를 사용하고, 두 줄 이상의 주석은 '/* */'를 사용한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
<head>
    <meta charset="EUC-KR">
    <title>선언문</title>
    <script>
        //한 줄 주석 입니다.
        /* 
            여러줄
            주석
            입니다
        */
        document.write("환영합니다");
    </script>
</head>
 
cs

자바스크립트는 html페이지 내에서 파일을 따로 분리하여 외부로부터 불러오는 형태가 가능하다.

1
2
3
4
5
6
<head>
    <meta charset="UTF-8">
    <title> 외부 자바스크립트 연동 </title>
    <script src="js/example.js"></script>
</head>
 
cs







JSP 페이지에서 게시판을 만들고, 게시글 내의 페이지에서 덧글 기능을 추가하여 보자.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//board 상세 내용 출력하는 부분
                    
                    String sql = "SELECT board_no,member_id,board_title,board_content,board_pw,board_date FROM board where board_no=?";
                    pstmt = conn.prepareStatement(sql);
                    pstmt.setString(1,sendBoardNo);
                    System.out.println(pstmt + " : confirm pstmt");
                    
                    rs = pstmt.executeQuery();
                    
                    
                    if(rs.next()) {
                %>
                        <div id="view_title_box">
                            <span><%=rs.getString(3%></span>
                            <span id="info"><%=rs.getString(2%> | 조회:208 | <%=rs.getString(6%></span>
                        </div>
                        <p id="view_content">
                            <%=rs.getString(4%>
                        </p>
                <%
                    }
                %>
cs


쿼리문은 글 번호가 일치하는 게시물의 번호, 글쓴이의 id, 글 제목, 글 내용, 글 비밀번호, 작성 시간의 부분을 조회하는 내용이다.


rs 객체에 담겨진 테이블은 rs.getString()에 의해 글의 제목, 작성자 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
<!-- 덧글 리스트 -->
                <!-- 페이징 or 덧글의 수가 5개까지 허용되도록 --> 
                <%
                    //덧글 리스트 select
                    String commentListQuery = "SELECT member_id, board_comment_content FROM board_comment WHERE board_no=?";
                    pstmt2 = conn.prepareStatement(commentListQuery);
                    pstmt2.setString(1, sendBoardNo);
                    System.out.println(pstmt2 + " : confirm pstmt2");
                    
                    //덧글의 갯수 select
                    String countListQuery = "SELECT count(*) as countList FROM board_comment where board_no=?";
                    pstmt3 = conn.prepareStatement(countListQuery);
                    pstmt3.setString(1, sendBoardNo);
                    
                    rs2 = pstmt2.executeQuery();
                    System.out.println(rs2 + " : confirm rs2");
                    
                    rs3 = pstmt3.executeQuery();
                    System.out.println(rs3 + " : confirm rs3");
                    
                    //덧글 갯수 변수에 저장
                    int countList = 0;
                    if(rs3.next()){
                        countList = rs3.getInt(1);
                    }
                %>
cs


덧글에 관련된 코드이다.


첫번째 쿼리는 글 번호가 일치하는 글의 작성자 id, 덧글들을 board_comment 테이블에서 조회하는 내용이다.


두번째 쿼리는 글 번호가 일치하는 board_comment 내의 모든 행의 갯수를 조회하는 내용이다.


그 후 rs3 객체에 담겨진 두번째 쿼리 실행의 결과 테이블은 countList 변수에 값이 담기게 된다.



                    //덧글 리스트 출력
                    while(rs2.next()){
                %>
                        <tr>
                            <td><%=rs2.getString(1%></td>
                            <td><%=rs2.getString(2%></td>
                        </tr>
                <%
                    }
                %>


덧글 리스트를 출력하는 코드로 rs2 객체내 테이블의 행을 조사하여 컬럼의 값들을 행의 마지막 까지 페이지에 출력하게 한다.


                <!-- 덧글 입력하는 폼 -->
                <form action="./insertCommentAction.jsp" method="post">
                    <div id="comment_box">
                        <img id="title_comment" src="img/title_comment.gif">
                        <textarea name="boardCommentContent"></textarea>
                        <%
                            //로그인 세션이 있을때만 덧글 작성 가능.
                            if(session.getAttribute("loginInfo"!= null){
                                //덧글 갯수가 5개 미만일때 글쓰기 버튼 표시
                                if(countList < 5) {
                        %>
                                    <input type="image" id="ok_ripple" src="img/ok_ripple.gif"><br>
                        <%
                                } else { //덧글갯수가 5개 이상이면 글쓰기 버튼 없애기
                        %>
                                    <img src="img/comment_limit_5.jpg" id="ok_ripple2">
                        <%
                                }
                            } else {//로그인 세션이 없을때는 로그인 먼저 하라는 그림 출력
                        %>
                                <img src="img/first_login.jpg" id="ok_ripple2">
                        <%                                
                            }
                        %>    
                        <input type="hidden" name="boardNo" value="<%=sendBoardNo %>"><br>
                        <input type="hidden" name="loginInfo" value="<%=session.getAttribute("loginInfo")%>">
                    </div>
                </form>

덧글을 입력하는 폼의 코드 부분이다.


폼에서 insertCommentAction.jsp페이지로 post 방식을 통해 값을 넘겨주도록 하였다.


로그인 세션이 있을때애는 덧글 작성확인 이미지 버튼이 표시되게 하였고,


없을때에는 로그인을 먼저 하라는 사진이 표시되도록 하였다.


그리고 덧글이 5개 이상일 경우에는 더 이상 덧글을 작성할 수 없다는 그림을 표시하게 하였다.


1
2
3
4
5
6
7
8
9
10
11
12
13
            // 덧글 사용 쿼리문 작성
            String insertCommentQuery = "INSERT INTO board_comment (board_no, board_comment_content, member_id) VALUES (?, ?, ?)";
            pstmt = conn.prepareStatement(insertCommentQuery);
            pstmt.setInt(1, boardNo);
            pstmt.setString(2, boardCommentContent);
            pstmt.setString(3, loginInfo);
            
            //쿼리문 실행
            pstmt.executeUpdate();
            
            //덧글 작성 글로 리다이렉트
            response.sendRedirect("./boardDetail.jsp?sendboardno=" + boardNo);
 
cs


boardDetail.jsp 페이지에서 전송된 정보를 받아서 mysql데이터 베이스에 입력하도록 하는 페이지다.


쿼리문은 글 번호, 덧글 내용, 작성자 id 컬럼에 입력값을 담아서 삽입하는 내용이다.


PreparedStatement 객체내 executeUpdate()메소드가 실행되어 삽입이 완료 되고, 


boardDetail.jsp의 글 번호에 해당하는 글로 리다이렉트 되도록 하였다.





덧글 리스트와 덧글 작성 부분이다.




덧글이 5개 이상이면 덧글쓰기 버튼이 이미지로 전환된다.


로그인을 하지 않은 상태에서는 로그인을 먼저 하라는 이미지가 출력된다.







이상 JSP를 활용하여 게시글에 덧글 기능을 만들어 보았다.


아직 초보라 실력이 매우 미숙하기에 너른 이해 바랍니다.

현재부터 X개월 이전의 자료를 검색할 때 사용


select * from tb_goods where g_date >= date_add(now(), interval -6 month)


XX일 이후로 지금 까지의 모든 자료를 검색할 때 사용

select * from tb_goods where g_date between '2018-01-15' and now()




'프로그래밍 > MySQL' 카테고리의 다른 글

SQL 오류 (1064)  (0) 2018.05.24
SQL update - where  (0) 2018.05.24
같은 이름의 데이터베이스를 중복 생성시 오류  (0) 2018.05.24
자료 저장소의 의미와 종류  (0) 2018.04.24
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
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!Doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
        <style>
            * {
                margin:0;
                padding:0;
            }
            ul {
                list-style-type:none;
            }
            body {
                font-family:"맑은 고딕", "돋움";
                font-size:12px;
                color:44444;
            }
            #login_box {
                width:220px;
                height:120px;
                border:solid 1px #bbbbbb;
                border-radius:15px;
                margin:10px 0 0 10px;
                padding:10px 0 0 15px;
            }
            h2 {
                font-family:"Arial";
                margin-bottom:10px;
            }
            #login_box input {
                width:100px;
                height:18px;
            }
            #id_pass, #login_btn {
                display:inline-block;
                vertical-align:top;
            }
            #id_pass span {
                display:inline-block;
                width:20px;
            }
            #pass {
                margin-top:3px;
            }
            #login_btn button {
                margin-left:5px;
                padding:12px;
                border-radius:5px;
            }
            #btns {
                margin:12px 0 0 0;
                text-decoration:underline;
            }
            #btns li {
                margin-left:10px;
                display:inline;
            }
        </style>
    </head>
    <body>
        <form action="./loginAction2.jsp" method="post">
            <div id="login_box">
                <h2>Member Login</h2>
                <ul id="input_button">
                    <li id="id_pass">
                        <ul>
                            <li>
                                <span>ID</span>
                                <input type="text" name="id">
                            </li>
                            <li id="pass">
                                <span>PW</span>
                                <input type="password" name="pw">
                            </li>
                        </ul>
                    </li>
                    <li id="login_btn">
                        <button>로그인</button>
                    </li>
                </ul>
                <ul id="btns">
                    <li>회원가입</li>
                    <li>아이디/비밀번호 찾기</li>
                </ul>
            </div>
        </form>
    </body>
</html>
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import = "java.sql.*"%>
<!Doctype html>
<%
    //request.setCharacterEncoding("EUC-KR");
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    String loginid = request.getParameter("id");
    String loginpw = request.getParameter("pw");
    System.out.println(loginid + "<---loginid");
    System.out.println(loginpw + "<---loginpw");
    
    Class.forName("com.mysql.jdbc.Driver");
    
    String dbaddress = "jdbc:mysql://localhost:3306/member_list?useUnicode=true&characterEncoding=euckr";
    String dbid = "root";
    String dbpw = "java0000";
    
    conn = DriverManager.getConnection(dbaddress, dbid, dbpw);
    System.out.println(conn + "<---conn");
    
    String sql = "SELECT dbid,dbpw,name,phone,email,address,memo,picture from join_member where dbid=? and dbpw=?";
    pstmt = conn.prepareStatement(sql);
    System.out.println(pstmt + "<---01 pstmt");
    
    pstmt.setString(1, loginid);
    pstmt.setString(2, loginpw);
    System.out.println(pstmt + "<---02 pstmt");
    
    rs = pstmt.executeQuery();
    System.out.println(rs + "<---rs");
    
    if(rs.next()) {
        rs.getString("dbid");
        rs.getString("name");
        rs.getString("phone");
        rs.getString("email");
        rs.getString("address");
        rs.getString("memo");
        rs.getString("picture");
        out.println("로그인 성공");
        System.out.println(rs.getString("dbid"));
        System.out.println(rs.getString("name"));
        System.out.println(rs.getString("phone"));
        System.out.println(rs.getString("email"));
        System.out.println(rs.getString("address"));
        System.out.println(rs.getString("memo"));
        System.out.println(rs.getString("picture"));
    } else {
        System.out.println("로그인 실패");
        response.sendRedirect("./loginForm2.jsp");
    }
 
%>
cs





setString(?의 번호, 입력변수) 메소드로 ?에 입력값을 대입해주지 않으면 


com.mysql.jdbc.JDBC4PreparedStatement@14ed38ee: SELECT dbid,dbpw,name,phone,email,address,memo,picture from join_member where dbid=** NOT SPECIFIED ** and dbpw=** NOT SPECIFIED **<---02 pstmt


id password를 입력해도 쿼리문에 값이 입력되지 않아서


java.sql.SQLException: No value specified for parameter 1


예외가 발생한다.



getRequestURI() : 페이지의 주소만 출력한다.



getRequestURL() : 페이지의 주소, 프로토콜, 포트번호까지 출력한다.



DDL (Data Definition Language) :

Data Definition Language is used to define database structure or schema. DDL is also used to specify additional properties of the data. The storage structure and access methods used by the database system by a set of statements in a special type of DDL called a data storage and definition language. These statements defines the implementation details of the database schema, which are usually hidden from the users. The data values stored in the database must satisfy certain consistency constraints.
For example, suppose the university requires that the account balance of a department must never be negative. The DDL provides facilities to specify such constraints. The database system checks these constraints every time the database is updated. In general, a constraint can be arbitrary predicate pertaining to the database. However, arbitrary predicates may be costly to the test. Thus, database system implements integrity constraints that can be tested with minimal overhead.

  1. Domain Constraints : A domain of possible values must be associated with every attribute (for example, integer types, character types, date/time types). Declaring an attribute to be of a particular domain acts as the constraints on the values that it can take.
  2. Referential Integrity : There are cases where we wish to ensure that a value appears in one relation for a given set of attributes also appear in a certain set of attributes in another relation i.e. Referential Integrity. For example, the department listed for each course must be one that actually exists.
  3. Assertions : An assertion is any condition that the database must always satisfy. Domain constraints and Integrity constraints are special form of assertions.
  4. Authorization : We may want to differentiate among the users as far as the type of access they are permitted on various data values in database. These differentiation are expressed in terms of Authorization. The most common being :
    read authorization – which allows reading but not modification of data ;
    insert authorization – which allow insertion of new data but not modification of existing data
    update authorization – which allows modification, but not deletion.

DML (Data Manipulation Language) :

DML statements are used for managing data with in schema objects.
DML are of two types –

  1. Procedural DMLs : require a user to specify what data are needed and how to get those data.
  2. Declerative DMLs (also referred as Non-procedural DMLs) : require a user to specify what data are needed without specifying how to get those data.

    Declerative DMLs are usually easier to learn and use than are procedural DMLs. However, since a user does not have to specify how to get the data, the database system has to figure out an efficient means of accessing data.


DCL (Data Control Language) :

A Data Control Language is a syntax similar to a computer programming language used to control access to data stored in a database (Authorization). In particular, it is a component of Structured Query Language (SQL).


The operations for which privileges may be granted to or revoked from a user or role apply to both the Data definition language (DDL) and the Data manipulation language (DML), and may include CONNECT, SELECT, INSERT, UPDATE, DELETE, EXECUTE and USAGE.


In the Oracle database, executing a DCL command issues an implicit commit. Hence, you cannot roll back the command.



TCL (Transaction Control Language) :

Transaction Control Language commands are used to manage transactions in database. These are used to manage the changes made by DML-statements. It also allows statements to be grouped together into logical transactions.




'프로그래밍 > ---DBMS---' 카테고리의 다른 글

관계 데이터 연산  (0) 2018.09.29
정규화란?  (0) 2018.09.29


Update시에 분명 문장을 정상적으로 작성한 것이라 생각했는데 계속 1064에러가 출력되었다.




set, where 같은 구분 명령어의 전에는 쉼표를 사용하면 구문 에러가 출력된다.

Update시에 다음 에러가 난다.




m_id필드가 primary key로 지정이 되어있는데 where로 설정해주지 않으면 중복문제가 발생한다.

'프로그래밍 > MySQL' 카테고리의 다른 글

날짜 관련 SELECT 쿼리문  (0) 2018.06.08
SQL 오류 (1064)  (0) 2018.05.24
같은 이름의 데이터베이스를 중복 생성시 오류  (0) 2018.05.24
자료 저장소의 의미와 종류  (0) 2018.04.24



SQL 오류 (1007) 메시지가 출력 되면서 database가 이미 존재하므로 생성할 수 없다는 창이 뜬다.

'프로그래밍 > MySQL' 카테고리의 다른 글

날짜 관련 SELECT 쿼리문  (0) 2018.06.08
SQL 오류 (1064)  (0) 2018.05.24
SQL update - where  (0) 2018.05.24
자료 저장소의 의미와 종류  (0) 2018.04.24


태그 선택자 : HTML 태그 이름을 이용하여 꾸밀 영역을 선택하는 것이다. 태그 선택자에 기술된 CSS 명령은 해당 태그가 사용된

모든 영역에 적용된다.



아이디와 아이디 선택자 : 특정 영역을 꾸밀 때 그 영역을 아이디로 지정하고  아이디 선택자를 사용하여 해당 영역을 선택할 수 있다.

아이디 선택자는 아이디 이름 앞에 #을 붙인다.



클래스와 클래스 선택자 : 특정한 한 영역을 지정하는 아이디와 달리 클래스는 여러 영역을 동시에 지정할 때 사용한다. 클래스로 지정한                                 영역은 클래스 선택자로 선택하고 CSS 명령으로 꾸밀 수 있다. 클래스 선택자는 클래스 이름으로 앞에 . 를 붙인다.


후손 선택자 : HTML 태그, 아이디, 클래스 내부의 영역을 지정할 때 사용한다. 후손 선택자를 적절히 사용하면 CSS 코드가 좀 더 간결해지고                     모듈화가 가능하여 CSS 코딩 작업을 수월하게 할 수 있다.


CSS 주석문 :  HTML 코드에 설명을 달기 위해 HTML 주석문을 사용하는 것과 마찬가지로 CSS 코드에 설명을 달때 CSS 주석문을 사용한다.

CSS 주석문은 /*로 시작하여 */로 끝난다.




출처 : HTML / CSS for beginner 황재호 지음



+ Recent posts