2016년 8월 4일 목요일

04day JSP

1. 게시판 + 아이콘 추가 + 24시간글 new이미지
 create table board2(
 seq            number                            not null   primary key,
 subject       varchar2(100)                     not null,
 writer          varchar2(12)                      not null,
 mail           varchar2(50),
 password    varchar2(12)                      not null,
 content      varchar2(2000),
 hit            number                            not null,
 wip           varchar2(15)                      not null,
 wdate        date                                not null,
 icon    varchar2(10)                          not null
 );


2. board_write1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script language='javascript'>
    function ChkForm(form) {
        //필수 입력값 검사
        if(document.wfrm.subject.value.trim() ==""){
            alert('제목을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.writer.value.trim() ==""){
            alert('이름을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <form action='board_write1_ok.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>제목</font> :
            </td>
            <td>
                <input type='text' name='subject' size='80' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>작성자</font> :
            </td>
            <td>
                이름&nbsp;&nbsp;<input type='text' name='writer' size='10' maxlength='10' class='form'>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='mail' size='40' maxlength='70' class='form'>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='password' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>내용</font> :
            </td>
            <td>
                <textarea name='content' style='width:620;height:300' class='form'></textarea>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>아이콘</font> :
            </td>
            <td style='padding:5'>
                <table width='100%' border='0' cellpadding='0' cellspacing='0'>
                <tr>
                    <td align='center'><img src='../images/emot/001.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/002.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/003.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/004.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/005.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/006.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/007.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/008.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/009.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/010.bmp' width='18' height='18'></td>
                </tr>
                <tr>
                    <td align='center'><input type='radio' name='icon' value='001.bmp' checked></td>
                    <td align='center'><input type='radio' name='icon' value='002.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='003.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='004.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='005.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='006.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='007.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='008.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='009.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='010.bmp'></td>
                </tr>
                <tr>
                    <td align='center'><img src='../images/emot/011.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/012.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/013.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/014.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/015.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/016.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/017.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/018.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/019.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/020.bmp' width='18' height='18'></td>
                </tr>
                <tr>
                    <td align='center'><input type='radio' name='icon' value='011.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='012.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='013.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='014.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='015.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='016.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='017.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='018.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='019.bmp'></td>
                    <td align='center'><input type='radio' name='icon' value='020.bmp'></td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>

        <table width='100%' cellpadding='0' cellspacing='0' border='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <input type='image' src='../images/btn_wri.gif' border='0'>&nbsp;
                <a href='board_list1.jsp'><img src='../images/btn_list.gif' border='0'></a>
            </td>
        </tr>
        </table>
        </form>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


3.board_write1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%-- 숨김페이지라서 HTML 코드 없음 --%>
<%
    request.setCharacterEncoding("utf-8");
    //클라이언트 정보 받기
    String subject =request.getParameter("subject");
    String writer =request.getParameter("writer");
    String mail =request.getParameter("mail");
    String password =request.getParameter("password");
    String content =request.getParameter("content");
    String wip = request.getRemoteAddr();  //클라이언트 아이피
    String icon =request.getParameter("icon");
    System.out.println(icon);
    
    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    int flag = 1;  //데이터베이스 입력 성공실패 여부  성공0, 실패 1
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "insert into board2 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate, ?)";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, subject);
        pstmt.setString(2, writer);
        pstmt.setString(3, mail);
        pstmt.setString(4, password);
        pstmt.setString(5, content);
        pstmt.setString(6, wip);
        pstmt.setString(7, icon);
        
        //executeUpdate 리턴 값: 영향 받은 행수
        int result = pstmt.executeUpdate();
        if(result ==1){
            flag =0;
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(pstmt !=null)pstmt.close();
        if(conn !=null)conn.close();
    }
    
    //성공시 리스트페이지 , 실패시 이전페이지로 이동 자바스크립트
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글쓰기에 성공했습니다')");
        out.println("location.href='board_list1.jsp';");
    }else{
        out.println("alert('글쓰기에 실패했습니다')");
        out.println("history.back()");
    }
    out.println("</script>");
    
%>


4.board_list1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    StringBuffer result = new StringBuffer();
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "select seq, subject, writer, to_char(wdate,'YY.MM.DD') wdate, hit, icon,trunc(sysdate-wdate) new24 from board2 order by seq desc";
        pstmt = conn.prepareStatement(sql);
        
        rs= pstmt.executeQuery();
        while(rs.next()){
            String seq = rs.getString("seq");
            String subject = rs.getString("subject");
            String writer = rs.getString("writer");
            String wdate = rs.getString("wdate");
            String hit = rs.getString("hit");
            String icon = rs.getString("icon");
            Boolean new24 = Integer.parseInt(rs.getString("new24"))<1;  //24시간 안의 글

            result.append("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            result.append("<tr>");
            result.append("    <td height='1'></td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td>");
            result.append("        <table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            result.append("            <tr height='25' onMouseOver=\"this.className='evencell'\" onMouseOut=\"this.className=''\">");
            result.append("                <td width='40' align='center'>"+seq+"</td>");
            result.append("                <td>");
            result.append("                    <span style='width:370' class='elltxt'>");
            result.append("                    <img src='../images/emot/"+icon+"' width='16' height='16' border='0' hspace='3'>");
            result.append("                        <a href='board_view1.jsp?seq="+seq+"'>"+subject+"</a>");
            result.append(new24?"                        <img src='../images/ico_n.gif' width='8' height='8' border='0' hspace='3'>":"");
            result.append("                    </span>");
            result.append("                </td>");
            result.append("                <td width='100' align='center'>"+writer+"</td>");
            result.append("                <td width='80' align='center'>"+wdate+"</td>");
            result.append("                <td width='50' align='center'>"+hit+"</td>");
            result.append("            </tr>");
            result.append("        </table>");
            result.append("    </td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td height='1'></td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td align='center' class='imgline'></td>");
            result.append("</tr>");
            result.append("</table>");            
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }

%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td align='center' class='gline'></td>
        </tr>
        <tr>
            <td align='center'>
                <table width='100%' border='0' cellpadding='0' cellspacing='0' class='titlecell'>
                <tr height='25' align='center'>
                    <td width='40'>No</td>
                    <td>제목</td>
                    <td width='100'>이름</td>
                    <td width='80'>등록일</td>
                    <td width='50'> 조회수</td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align='center' class='gline'></td>
        </tr>
        <tr>
            <td height='3'></td>
        </tr>
        </table>

        <!-- 테이블 자리 -->
        <%= result %>

        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <a href='board_write1.jsp'><img src='../images/btn_wri.gif' border='0'></a>
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


5.board_view1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>

<%
    //선택한 글의 seq 받아오기
    request.setCharacterEncoding("utf-8");
    String seq = request.getParameter("seq");
    
    String subject ="";
    String writer = "";
    String mail = "";
    String wip = "";
    String wdate = "";
    String hit = "";
    String content = "";
    String icon = "";
    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        //조회수 증가
        String sql = "update board1 set hit=hit+1 where seq=?";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        pstmt.executeUpdate();
        
        //view창 출력
        sql = "select subject, writer, mail, wip, wdate, hit, content, icon from board2 where seq=?";
        pstmt=conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        
        rs = pstmt.executeQuery();
        if(rs.next()){
            subject = rs.getString("subject");
            writer = rs.getString("writer");
            mail = rs.getString("mail")==null?"":rs.getString("mail");   //공백처리
            wip = rs.getString("wip");
            wdate = rs.getString("wdate");
            hit = rs.getString("hit");
            content = rs.getString("content")==null?"":rs.getString("content").replaceAll("\n", "<br>"); //엔터키 처리
            icon = rs.getString("icon");
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }
%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <table width='100%' cellpadding='0' cellspacing='0' border='0' align='center'>
        <tr>
            <td height='25'><font class='titdot'>&#149;&nbsp;</font><font class='title'>제목</font> | <%=subject %><img src=<%="../images/emot/"+icon %> width='16' height='16' border='0' hspace='3'></td>
        </tr>
        <tr>
            <td class='imgline'></td>
        </tr>
        <tr>
            <td height='25'><font class='titdot'>&#149;&nbsp;</font><font class='title'>이름</font> | <%=writer %>(<%=mail %>) (<%=wip %>)</td>
        </tr>
        <tr>
            <td class='imgline'></td>
        </tr>
        <tr>
            <td height='25'>
                <table width='100%' cellpadding='0' cellspacing='0' border='0' align='center'>
                <tr>
                    <td><font class='titdot'>&#149;</font><font class='title'> 날짜</font> | <%=wdate %></td>
                    <td align='right'><font class='titdot'>&#149;&nbsp;</font><font class='title'>조회</font> | <%=hit %></td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td  class='imgline'></td>
        </tr>
        <tr>
            <td height='100'><%=content %></td>
        </tr>
        </table>

        <table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>
        <tr>
            <td id='tailarea'></td>
        </tr>
        </table>

        <table width='100%' border='0' cellspacing='1' cellpadding='1'>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        <tr>
            <td width='500' height='30'>
                <a href='board_write1.jsp'><img src='../images/btn_wri.gif' border='0'></a>                  
                <a href='board_modify1.jsp?seq=<%=seq%>'><img src='../images/btn_mod.gif' border='0'></a> <%-- 글수정 URL seq녛기 --%>
                <a href='board_delete1.jsp?seq=<%=seq%>'><img src='../images/btn_del.gif' border='0'></a> <%-- 글삭제 URL seq녛기 --%>
            </td>
            <td align='right'>
                <a href='board_list1.jsp'><img src='../images/btn_list.gif' border='0'></a>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


6.board_delete1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%
    //선택한 글의 seq 받아오기
    request.setCharacterEncoding("utf-8");
    String seq = request.getParameter("seq");
    
    String subject ="";
    String writer = "";
    String mail = "";

    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        //delete창 출력
        String sql = "select subject, writer, mail from board2 where seq=?";
        pstmt=conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        
        rs = pstmt.executeQuery();
        if(rs.next()){
            subject = rs.getString("subject");
            writer = rs.getString("writer");
            mail = rs.getString("mail")==null?"":rs.getString("mail");
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }
%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script type="text/javascript">
    function ChkForm(form) {
        //필수 입력값 검사
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <form action='board_delete1_ok.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <input type='hidden' name='seq' value='<%=seq%>'>  <%-- seq를 히든으로 보냄 --%>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>제목</font> :
            </td>
            <td>
                <input type='text' name='subject' value='<%=subject %>' size='80' class='form' readonly>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>작성자</font> :
            </td>
            <td>
                이름&nbsp;&nbsp;<input type='text' name='writer' value='<%=writer %>' size='10' maxlength='10' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='mail' value='<%=mail %>' size='40' maxlength='70' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='password' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>

        <table width='100%' cellpadding='0' cellspacing='0' border='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <input type='image' src='../images/btn_del.gif' border='0'>&nbsp;
                <a href='board_list1.jsp'><img src='../images/btn_list.gif' border='0'></a>&nbsp;
                <a href='javascript:history.back();'><img src='../images/btn_view.gif' border='0'></a>
            </td>
        </tr>
        </table>
        </form>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


7.board_delete1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%-- 숨김페이지라서 HTML 코드 없음 --%>
<%
    request.setCharacterEncoding("utf-8");
    //클라이언트 정보 받기
    String seq =request.getParameter("seq");
    String password =request.getParameter("password");
    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    int flag = 2;  //데이터베이스 입력 성공실패 여부  성공0, 비번다름 1
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "delete from board2 where seq=? and password=?";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        pstmt.setString(2, password);
        
        //executeUpdate 리턴 값: 영향 받은 행수
        int result = pstmt.executeUpdate();
        if(result ==0){
            flag =1;
        }else if(result ==1){
            flag =0;
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(pstmt !=null)pstmt.close();
        if(conn !=null)conn.close();
    }
    
    //성공시 리스트페이지 , 실패시 이전페이지로 이동 자바스크립트
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글삭제에 성공했습니다')");
        out.println("location.href='board_list1.jsp';");
    }else if(flag==1){
        out.println("alert('비밀번호가 잘못되었습니다.')");
        out.println("history.back();");
    }else{
        out.println("alert('글삭제에 실패했습니다')");
        out.println("history.back();");
    }
    out.println("</script>");
    
%>


8.board_modify1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>

<%
    //선택한 글의 seq 받아오기
    request.setCharacterEncoding("utf-8");
    String seq = request.getParameter("seq");
    
    String subject ="";
    String writer = "";
    String mail = "";
    String content = "";
    String icon = "";

    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        //modify창 출력
        String sql = "select subject, writer, mail, content, icon from board2 where seq=?";
        pstmt=conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        
        rs = pstmt.executeQuery();
        if(rs.next()){
            subject = rs.getString("subject");
            writer = rs.getString("writer");
            mail = rs.getString("mail")==null?"":rs.getString("mail");
            content = rs.getString("content")==null?"":rs.getString("content");
            icon = rs.getString("icon");
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }
%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script language='javascript'>
    function ChkForm(form) {
        //필수 입력값 검사
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <form action='board_modify1_ok.jsp' method='get' name='wfrm' onSubmit='return ChkForm(this)'>
        <input type='hidden' name='seq' value='<%=seq%>'>  <%-- seq를 히든으로 보냄 --%>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>제목</font> :
            </td>
            <td>
                <input type='text' name='subject' value='<%=subject %>' size='80' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>작성자</font> :
            </td>
            <td>
                이름&nbsp;&nbsp;<input type='text' name='writer' value='<%=writer %>' size='10' maxlength='10' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='mail' value='<%=mail %>' size='40' maxlength='70' class='form'>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='password' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>내용</font> :
            </td>
            <td>
                <textarea name='content' style='width:620;height:300' class='form'><%=content %></textarea>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>아이콘</font> :
            </td>
            <td style='padding:5'>
                <table width='100%' border='0' cellpadding='0' cellspacing='0'>
                <tr>
                    <td align='center'><img src='../images/emot/001.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/002.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/003.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/004.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/005.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/006.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/007.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/008.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/009.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/010.bmp' width='18' height='18'></td>
                </tr>
                <tr>
                    <td align='center'><input type='radio' name='icon' value='001.bmp' <%= icon.equals("001.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='002.bmp' <%= icon.equals("002.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='003.bmp' <%= icon.equals("003.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='004.bmp' <%= icon.equals("004.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='005.bmp' <%= icon.equals("005.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='006.bmp' <%= icon.equals("006.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='007.bmp' <%= icon.equals("007.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='008.bmp' <%= icon.equals("008.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='009.bmp' <%= icon.equals("009.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='010.bmp' <%= icon.equals("010.bmp")?"checked":"" %>></td>
                </tr>
                <tr>
                    <td align='center'><img src='../images/emot/011.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/012.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/013.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/014.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/015.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/016.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/017.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/018.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/019.bmp' width='18' height='18'></td>
                    <td align='center'><img src='../images/emot/020.bmp' width='18' height='18'></td>
                </tr>
                <tr>
                    <td align='center'><input type='radio' name='icon' value='011.bmp' <%= icon.equals("011.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='012.bmp' <%= icon.equals("012.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='013.bmp' <%= icon.equals("013.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='014.bmp' <%= icon.equals("014.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='015.bmp' <%= icon.equals("015.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='016.bmp' <%= icon.equals("016.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='017.bmp' <%= icon.equals("017.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='018.bmp' <%= icon.equals("018.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='019.bmp' <%= icon.equals("019.bmp")?"checked":"" %>></td>
                    <td align='center'><input type='radio' name='icon' value='020.bmp' <%= icon.equals("020.bmp")?"checked":"" %>></td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>

        <table width='100%' cellpadding='0' cellspacing='0' border='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <input type='image' src='../images/btn_mod.gif' border='0'>&nbsp;
                <a href='board_list1.jsp'><img src='../images/btn_list.gif' border='0'></a>&nbsp;
                <a href='javascript:history.back();'><img src='../images/btn_view.gif' border='0'></a>
            </td>
        </tr>
        </table>
        </form>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


9.board_modify1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%-- 숨김페이지라서 HTML 코드 없음 --%>
<%
    request.setCharacterEncoding("utf-8");
    //클라이언트 정보 받기
    String seq =request.getParameter("seq");
    String subject =request.getParameter("subject");
    String mail =request.getParameter("mail");
    String password =request.getParameter("password");
    String content =request.getParameter("content");
    String icon =request.getParameter("icon");
    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    int flag = 2;  //데이터베이스 입력 성공실패 여부  성공0, 비번다름 1
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "update board1 set subject=?, mail=?, content=?, icon=? where seq=? and password=?";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, subject);
        pstmt.setString(2, mail);
        pstmt.setString(3, content);
        pstmt.setString(4, icon);
        pstmt.setString(5, seq);
        pstmt.setString(6, password);
        
        //executeUpdate 리턴 값: 영향 받은 행수
        int result = pstmt.executeUpdate();
        if(result ==0){
            flag =1;
        }else if(result ==1){
            flag =0;
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(pstmt !=null)pstmt.close();
        if(conn !=null)conn.close();
    }
    
    //성공시 리스트페이지 , 실패시 이전페이지로 이동 자바스크립트
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글수정에 성공했습니다')");
        out.println("location.href='board_list1.jsp';");
    }else if(flag==1){
        out.println("alert('비밀번호가 잘못되었습니다.')");
        out.println("history.back();");
    }else{
        out.println("alert('글수정에 실패했습니다')");
        out.println("history.back();");
    }
    out.println("</script>");
    
%>





10.페이지 넘기기 리스트 만들기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%
    request.setCharacterEncoding("utf-8");

    int cpage = 1;
    if(request.getParameter("cpage")!=null && !request.getParameter("cpage").equals("")){
        cpage = Integer.parseInt(request.getParameter("cpage"));
    }
    //페이지당 출력 데이터 갯수
    int recordPerPage =10;
    //전체 데이터 갯수
    int totalRecord = 0;
    //전체 페이지 갯수
    int totalPage = 1;
    //페이지당 블럭 갯수
    int blockPerPage = 5;
    
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    StringBuffer result = new StringBuffer();
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "select seq, subject, writer, to_char(wdate,'YY.MM.DD') wdate, hit from board1 order by seq desc";
        //Resultset 옵션주기  //TYPE_SCROLL_INSENSITIVE 이전행 되돌리기 가능  //CONCUR_READ_ONLY 행읽기만 가능 수정불가
        pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        
        rs= pstmt.executeQuery();
        
        //전체데이터 갯수
        rs.last(); //마지막 데이터를 읽음
        totalRecord = rs.getRow(); //마지막 데이터 행번호를 가져옴
        rs.beforeFirst(); //데이터를 다시 처음으로 올림
        
        //전체 페이지 갯수
        totalPage = ((totalRecord-1)/recordPerPage) +1;
        
        //페이지를 넘길떄 처음 읽을 데이터의 행   0,10,20,30,40,...
        int skip=(cpage-1)*recordPerPage;
        //ResultSet에 읽고싶은 위치를 지정
        if(skip!=0)rs.absolute(skip);
        
        //recordPerPage만큼 짤려서 화면에 출력
        for(int i=0; i<recordPerPage && rs.next();i++){
            String seq = rs.getString("seq");
            String subject = rs.getString("subject");
            String writer = rs.getString("writer");
            String wdate = rs.getString("wdate");
            String hit = rs.getString("hit");
            
            result.append("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            result.append("<tr>");
            result.append("    <td height='1'></td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td>");
            result.append("        <table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            result.append("            <tr height='25' onMouseOver=\"this.className='evencell'\" onMouseOut=\"this.className=''\">");
            result.append("                <td width='40' align='center'>"+seq+"</td>");
            result.append("                <td>");
            result.append("                    <span style='width:370' class='elltxt'>");
            result.append("                        <a href='board_view1.jsp?seq="+seq+"'>"+subject+"</a>");
            result.append("                        <img src='../images/ico_n.gif' width='8' height='8' border='0' hspace='3'>");
            result.append("                    </span>");
            result.append("                </td>");
            result.append("                <td width='100' align='center'>"+writer+"</td>");
            result.append("                <td width='80' align='center'>"+wdate+"</td>");
            result.append("                <td width='50' align='center'>"+hit+"</td>");
            result.append("            </tr>");
            result.append("        </table>");
            result.append("    </td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td height='1'></td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td align='center' class='imgline'></td>");
            result.append("</tr>");
            result.append("</table>");            
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }

%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td align='center' class='gline'></td>
        </tr>
        <tr>
            <td align='center'>
                <table width='100%' border='0' cellpadding='0' cellspacing='0' class='titlecell'>
                <tr height='25' align='center'>
                    <td width='40'>No</td>
                    <td>제목</td>
                    <td width='100'>이름</td>
                    <td width='80'>등록일</td>
                    <td width='50'>조회수</td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align='center' class='gline'></td>
        </tr>
        <tr>
            <td height='3'></td>
        </tr>
        </table>
        
<!-- 리스트 시작 -->
<%= result %>
<!-- 리스트 끝 -->

        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='500' height='30'>
<!-- 페이지 네비게이션 시작 -->
<%
    //화면 하단에 보이는 페이지 리스트 갯수
    int startBlock = ((cpage-1)/blockPerPage)*blockPerPage+1;
    int endBlock =startBlock+blockPerPage-1;
    if(endBlock >=totalPage){
        endBlock = totalPage;
    }
%>
<%
    //블럭 옮기기
    if(startBlock==1){
        out.println("<img src='../images/moveset/p_left_arrow_01_off.gif' align='absmiddle' hspace='2' border='0'>");
    }else{
        out.println("<a href='board_list1.jsp?cpage="+(startBlock-blockPerPage)+"'><img src='../images/moveset/p_left_arrow_01.gif' align='absmiddle' hspace='2' border='0'></a>");
    }
%>
                
    <%
        //페이지 옮기기 //page가 1일때는 이전페이지로 못감, 화살표 색깔off로 바뀜
        if(cpage==1){
            out.println("<img src='../images/moveset/p_left_arrow_02_off.gif' align='absmiddle' hspace='8' border='0'>");
        }else{
            out.println("<a href='board_list1.jsp?cpage="+(cpage-1)+"'><img src='../images/moveset/p_left_arrow_02.gif' align='absmiddle' hspace='8' border='0'></a>");
        }
    %>
                

                <img src='../images/moveset/p_orange.gif' align='absmiddle' hspace='3' border='0'>
        <%
            for(int i=startBlock;i<=endBlock; i++){
                if(cpage==i){
                    out.println("<b><u>["+i+"]</u></b>&nbsp;");
                }else{
                    out.println("<a href='board_list1.jsp?cpage="+i+"'>"+i+"</a>&nbsp;");
                }
                
            }
        %>
                <img src='../images/moveset/p_orange.gif' align='absmiddle' hspace='3' border='0'>
    <%
        //페이지 옮기기 //page가 끝페이지일때  다음 페이지로 못감, 화살표 색깔off로 바뀜
        if(cpage==totalPage){
            out.println("<img src='../images/moveset/p_right_arrow_02_off.gif' align='absmiddle' hspace='8' border='0'>");
        }else{
            out.println("<a href='board_list1.jsp?cpage="+(cpage+1)+"'><img src='../images/moveset/p_right_arrow_02.gif' align='absmiddle' hspace='2' border='0'></a>");
        }
    %>
<%
    //블럭 옮기기
    if(endBlock==totalPage){
        out.println("<img src='../images/moveset/p_right_arrow_01_off.gif' align='absmiddle' hspace='2' border='0'>");
    }else{
        out.println("<a href='board_list1.jsp?cpage="+(startBlock+blockPerPage)+"'><img src='../images/moveset/p_right_arrow_01.gif' align='absmiddle' hspace='2' border='0'></a>");
    }
%>
<!-- 페이지 네비게이션 끝 -->    
            </td>        
            <td align='right'>
                <a href='board_write1.jsp'><img src='../images/btn_wri.gif' border='0'></a>
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>








11.board_list1 목록보기를 할때 현재 페이지로 되돌리기 작업
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%
    request.setCharacterEncoding("utf-8");

    int cpage = 1;
    if(request.getParameter("cpage")!=null && !request.getParameter("cpage").equals("")){
        cpage = Integer.parseInt(request.getParameter("cpage"));
    }
    //페이지당 출력 데이터 갯수
    int recordPerPage =10;
    //전체 데이터 갯수
    int totalRecord = 0;
    //전체 페이지 갯수
    int totalPage = 1;
    //페이지당 블럭 갯수
    int blockPerPage = 5;
    
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    StringBuffer result = new StringBuffer();
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "select seq, subject, writer, to_char(wdate,'YY.MM.DD') wdate, hit from board1 order by seq desc";
        //Resultset 옵션주기
        pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        
        rs= pstmt.executeQuery();
        
        //전체데이터 갯수
        rs.last(); //마지막 데이터를 읽음
        totalRecord = rs.getRow(); //마지막 데이터 행번호를 가져옴
        rs.beforeFirst(); //데이터를 다시 처음으로 올림
        
        //전체 페이지 갯수
        totalPage = ((totalRecord-1)/recordPerPage) +1;
        
        //페이지를 넘길떄 처음 읽을 데이터의 행   0,10,20,30,40,...
        int skip=(cpage-1)*recordPerPage;
        //ResultSet에 읽고싶은 위치를 지정
        if(skip!=0)rs.absolute(skip);
        
        //recordPerPage만큼 짤려서 화면에 출력
        for(int i=0; i<recordPerPage && rs.next();i++){
            String seq = rs.getString("seq");
            String subject = rs.getString("subject");
            String writer = rs.getString("writer");
            String wdate = rs.getString("wdate");
            String hit = rs.getString("hit");
            
            result.append("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            result.append("<tr>");
            result.append("    <td height='1'></td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td>");
            result.append("        <table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            result.append("            <tr height='25' onMouseOver=\"this.className='evencell'\" onMouseOut=\"this.className=''\">");
            result.append("                <td width='40' align='center'>"+seq+"</td>");
            result.append("                <td>");
            result.append("                    <span style='width:370' class='elltxt'>");
            result.append("                        <a href='board_view1.jsp?seq="+seq+"&cpage="+cpage+"'>"+subject+"</a>");
            result.append("                        <img src='../images/ico_n.gif' width='8' height='8' border='0' hspace='3'>");
            result.append("                    </span>");
            result.append("                </td>");
            result.append("                <td width='100' align='center'>"+writer+"</td>");
            result.append("                <td width='80' align='center'>"+wdate+"</td>");
            result.append("                <td width='50' align='center'>"+hit+"</td>");
            result.append("            </tr>");
            result.append("        </table>");
            result.append("    </td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td height='1'></td>");
            result.append("</tr>");
            result.append("<tr>");
            result.append("    <td align='center' class='imgline'></td>");
            result.append("</tr>");
            result.append("</table>");            
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }

%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td align='center' class='gline'></td>
        </tr>
        <tr>
            <td align='center'>
                <table width='100%' border='0' cellpadding='0' cellspacing='0' class='titlecell'>
                <tr height='25' align='center'>
                    <td width='40'>No</td>
                    <td>제목</td>
                    <td width='100'>이름</td>
                    <td width='80'>등록일</td>
                    <td width='50'>조회수</td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align='center' class='gline'></td>
        </tr>
        <tr>
            <td height='3'></td>
        </tr>
        </table>
        
<!-- 리스트 시작 -->
<%= result %>
<!-- 리스트 끝 -->

        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='500' height='30'>
<!-- 페이지 네비게이션 시작 -->
<%
    //화면 하단에 보이는 페이지 리스트 갯수
    int startBlock = ((cpage-1)/blockPerPage)*blockPerPage+1;
    int endBlock =startBlock+blockPerPage-1;
    if(endBlock >=totalPage){
        endBlock = totalPage;
    }
%>
<%
    //블럭 옮기기
    if(startBlock==1){
        out.println("<img src='../images/moveset/p_left_arrow_01_off.gif' align='absmiddle' hspace='2' border='0'>");
    }else{
        out.println("<a href='board_list1.jsp?cpage="+(startBlock-blockPerPage)+"'><img src='../images/moveset/p_left_arrow_01.gif' align='absmiddle' hspace='2' border='0'></a>");
    }
%>
                
    <%
        //페이지 옮기기 //page가 1일때는 이전페이지로 못감, 화살표 색깔off로 바뀜
        if(cpage==1){
            out.println("<img src='../images/moveset/p_left_arrow_02_off.gif' align='absmiddle' hspace='8' border='0'>");
        }else{
            out.println("<a href='board_list1.jsp?cpage="+(cpage-1)+"'><img src='../images/moveset/p_left_arrow_02.gif' align='absmiddle' hspace='8' border='0'></a>");
        }
    %>
                

                <img src='../images/moveset/p_orange.gif' align='absmiddle' hspace='3' border='0'>
        <%
            for(int i=startBlock;i<=endBlock; i++){
                if(cpage==i){
                    out.println("<b><u>["+i+"]</u></b>&nbsp;");
                }else{
                    out.println("<a href='board_list1.jsp?cpage="+i+"'>"+i+"</a>&nbsp;");
                }
                
            }
        %>
                <img src='../images/moveset/p_orange.gif' align='absmiddle' hspace='3' border='0'>
    <%
        //페이지 옮기기 //page가 끝페이지일때  다음 페이지로 못감, 화살표 색깔off로 바뀜
        if(cpage==totalPage){
            out.println("<img src='../images/moveset/p_right_arrow_02_off.gif' align='absmiddle' hspace='8' border='0'>");
        }else{
            out.println("<a href='board_list1.jsp?cpage="+(cpage+1)+"'><img src='../images/moveset/p_right_arrow_02.gif' align='absmiddle' hspace='2' border='0'></a>");
        }
    %>
<%
    //블럭 옮기기
    if(endBlock==totalPage){
        out.println("<img src='../images/moveset/p_right_arrow_01_off.gif' align='absmiddle' hspace='2' border='0'>");
    }else{
        out.println("<a href='board_list1.jsp?cpage="+(startBlock+blockPerPage)+"'><img src='../images/moveset/p_right_arrow_01.gif' align='absmiddle' hspace='2' border='0'></a>");
    }
%>
<!-- 페이지 네비게이션 끝 -->    
            </td>        
            <td align='right'>
                <a href='board_write1.jsp?cpage=<%=cpage%>'><img src='../images/btn_wri.gif' border='0'></a>
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


12.board_write1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    request.setCharacterEncoding("utf-8");
    String cpage = request.getParameter("cpage");
%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script type="text/javascript">
    function ChkForm() {
        //필수 입력값 검사
        if(document.wfrm.subject.value.trim() ==""){
            alert('제목을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.writer.value.trim() ==""){
            alert('이름을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <form action='board_write1_ok.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>제목</font> :
            </td>
            <td>
                <input type='text' name='subject' size='80' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>작성자</font> :
            </td>
            <td>
                이름&nbsp;&nbsp;<input type='text' name='writer' size='10' maxlength='10' class='form'>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='mail' size='40' maxlength='70' class='form'>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='password' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>내용</font> :
            </td>
            <td>
                <textarea name='content' style='width:620;height:300' class='form'></textarea>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>

        <table width='100%' cellpadding='0' cellspacing='0' border='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <input type='image' src='../images/btn_wri.gif' border='0'>&nbsp;
                <a href='board_list1.jsp?cpage=<%=cpage %>'><img src='../images/btn_list.gif' border='0'></a>
            </td>
        </tr>
        </table>
        </form>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


13.board_view1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>

<%
    //선택한 글의 seq 받아오기
    request.setCharacterEncoding("utf-8");
    String seq = request.getParameter("seq");
    String cpage = request.getParameter("cpage");
    
    String subject ="";
    String writer = "";
    String mail = "";
    String wip = "";
    String wdate = "";
    String hit = "";
    String content = "";
    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        //조회수 증가
        String sql = "update board1 set hit=hit+1 where seq=?";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        pstmt.executeUpdate();
        
        //view창 출력
        sql = "select subject, writer, mail, wip, wdate, hit, content from board1 where seq=?";
        pstmt=conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        
        rs = pstmt.executeQuery();
        if(rs.next()){
            subject = rs.getString("subject");
            writer = rs.getString("writer");
            mail = rs.getString("mail")==null?"":rs.getString("mail");   //공백처리
            wip = rs.getString("wip");
            wdate = rs.getString("wdate");
            hit = rs.getString("hit");
            content = rs.getString("content")==null?"":rs.getString("content").replaceAll("\n", "<br>"); //엔터키 처리
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }
%>

<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <table width='100%' cellpadding='0' cellspacing='0' border='0' align='center'>
        <tr>
            <td height='25'><font class='titdot'>&#149;&nbsp;</font><font class='title'>제목</font> | <%=subject %></td>
        </tr>
        <tr>
            <td class='imgline'></td>
        </tr>
        <tr>
            <td height='25'><font class='titdot'>&#149;&nbsp;</font><font class='title'>이름</font> | <%=writer %>(<%=mail %>) (<%=wip %>)</td>
        </tr>
        <tr>
            <td class='imgline'></td>
        </tr>
        <tr>
            <td height='25'>
                <table width='100%' cellpadding='0' cellspacing='0' border='0' align='center'>
                <tr>
                    <td><font class='titdot'>&#149;</font><font class='title'> 날짜</font> | <%=wdate %></td>
                    <td align='right'><font class='titdot'>&#149;&nbsp;</font><font class='title'>조회</font> | <%=hit %></td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td  class='imgline'></td>
        </tr>
        <tr>
            <td height='100'><%=content %></td>
        </tr>
        </table>

        <table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>
        <tr>
            <td id='tailarea'></td>
        </tr>
        </table>

        <table width='100%' border='0' cellspacing='1' cellpadding='1'>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        <tr>
            <td width='500' height='30'>
                <a href='board_write1.jsp?cpage=<%=cpage %>'><img src='../images/btn_wri.gif' border='0'></a>                  
                <a href='board_modify1.jsp?seq=<%=seq%>&cpage=<%=cpage %>'><img src='../images/btn_mod.gif' border='0'></a> <%-- 글수정 URL seq녛기 --%>
                <a href='board_delete1.jsp?seq=<%=seq%>&cpage=<%=cpage %>'><img src='../images/btn_del.gif' border='0'></a> <%-- 글삭제 URL seq녛기 --%>
            </td>
            <td align='right'>
                <a href='board_list1.jsp?cpage=<%=cpage %>'><img src='../images/btn_list.gif' border='0'></a>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


14.borad_delete1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>

<%
    //선택한 글의 seq 받아오기
    request.setCharacterEncoding("utf-8");
    String seq = request.getParameter("seq");
    String cpage = request.getParameter("cpage");
    
    String subject ="";
    String writer = "";
    String mail = "";

    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        //delete창 출력
        String sql = "select subject, writer, mail from board1 where seq=?";
        pstmt=conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        
        rs = pstmt.executeQuery();
        if(rs.next()){
            subject = rs.getString("subject");
            writer = rs.getString("writer");
            mail = rs.getString("mail")==null?"":rs.getString("mail");
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }
%>

<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script type="text/javascript">
    function ChkForm(form) {
        //필수 입력값 검사
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <form action='board_delete1_ok.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <input type='hidden' name='seq' value='<%=seq%>'>  <%-- seq를 히든으로 보냄 --%>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>제목</font> :
            </td>
            <td>
                <input type='text' name='subject' value='<%=subject %>' size='80' class='form' readonly>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>작성자</font> :
            </td>
            <td>
                이름&nbsp;&nbsp;<input type='text' name='writer' value='<%=writer %>' size='10' maxlength='10' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='mail' value='<%=mail %>' size='40' maxlength='70' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='password' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>

        <table width='100%' cellpadding='0' cellspacing='0' border='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <input type='image' src='../images/btn_del.gif' border='0'>&nbsp;
                <a href='board_list1.jsp?cpage=<%=cpage %>'><img src='../images/btn_list.gif' border='0'></a>&nbsp;
                <a href='javascript:history.back();'><img src='../images/btn_view.gif' border='0'></a>
            </td>
        </tr>
        </table>
        </form>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


15.board_modify1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>

<%
    //선택한 글의 seq 받아오기
    request.setCharacterEncoding("utf-8");
    String seq = request.getParameter("seq");
    String cpage = request.getParameter("cpage");
    
    String subject ="";
    String writer = "";
    String mail = "";
    String content = "";

    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        //modify창 출력
        String sql = "select subject, writer, mail,content from board1 where seq=?";
        pstmt=conn.prepareStatement(sql);
        pstmt.setString(1, seq);
        
        rs = pstmt.executeQuery();
        if(rs.next()){
            subject = rs.getString("subject");
            writer = rs.getString("writer");
            mail = rs.getString("mail")==null?"":rs.getString("mail");
            content = rs.getString("content")==null?"":rs.getString("content");
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(rs!=null) rs.close();
        if(pstmt!=null) pstmt.close();
        if(conn!=null) conn.close();
    }
%>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script type="text/javascript">
    function ChkForm(form) {
        //필수 입력값 검사
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
</head>

<body bgcolor='#ffffff' topmargin='5' rightmargin='0' leftmargin='5' bottommargin='10'>

<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='23' bgcolor='#f0f0f0' align='right'></td>
</tr>
<tr>
    <td bgcolor='#ffffff' style='padding:20'>
        <form action='board_modify1_ok.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <input type='hidden' name='seq' value='<%=seq%>'>  <%-- seq를 히든으로 보냄 --%>
        <input type='hidden' name='cpage' value='<%=cpage%>'>  <%-- cpage를 히든으로 보냄 --%>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>제목</font> :
            </td>
            <td>
                <input type='text' name='subject' value='<%=subject %>' size='80' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>작성자</font> :
            </td>
            <td>
                이름&nbsp;&nbsp;<input type='text' name='writer' value='<%=writer %>' size='10' maxlength='10' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='mail' value='<%=mail %>' size='40' maxlength='70' class='form'>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='password' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='70' style='padding:5' valign='top' align='right'>
                <font class='titdot'>&#149;&nbsp;</font>
                <font class='title'>내용</font> :
            </td>
            <td>
                <textarea name='content' style='width:620;height:300' class='form'><%=content %></textarea>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='gline'></td>
        </tr>
        </table>

        <table width='100%' cellpadding='0' cellspacing='0' border='0'>
        <tr>
            <td width='500' height='30'>&nbsp;</td>
            <td align='right'>
                <input type='image' src='../images/btn_mod.gif' border='0'>&nbsp;
                <a href='board_list1.jsp?cpage=<%=cpage %>'><img src='../images/btn_list.gif' border='0'></a>&nbsp;
                <a href='javascript:history.back();'><img src='../images/btn_view.gif' border='0'></a>
            </td>
        </tr>
        </table>
        </form>
    </td>
</tr>
</table>        
        
<table width='750px' border='0' cellpadding='0' cellspacing='0' align='center'>
<tr>
    <td height='15' bgcolor='#f0f0f0' style='padding:5' align='center'></td>
</tr>
</table>

</body>
</html>


16.board_modify1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.SQLException" %>

<%@ page import = "javax.naming.Context" %>
<%@ page import = "javax.naming.InitialContext" %>
<%@ page import = "javax.naming.NamingException" %>
<%@ page import = "javax.sql.DataSource" %>
<%-- 숨김페이지라서 HTML 코드 없음 --%>
<%
    request.setCharacterEncoding("utf-8");
    //클라이언트 정보 받기
    String seq =request.getParameter("seq");
    String cpage = request.getParameter("cpage");
    String subject =request.getParameter("subject");
    String mail =request.getParameter("mail");
    String password =request.getParameter("password");
    String content =request.getParameter("content");
    
    //데이터베이스 연결
    Connection conn = null;
    PreparedStatement pstmt = null;
    int flag = 2;  //데이터베이스 입력 성공실패 여부  성공0, 비번다름 1
    
    try{
        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        
        conn = dataSource.getConnection();
        
        String sql = "update board1 set subject=?, mail=?, content=? where seq=? and password=?";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, subject);
        pstmt.setString(2, mail);
        pstmt.setString(3, content);
        pstmt.setString(4, seq);
        pstmt.setString(5, password);
        
        //executeUpdate 리턴 값: 영향 받은 행수
        int result = pstmt.executeUpdate();
        if(result ==0){
            flag =1;
        }else if(result ==1){
            flag =0;
        }
        
    }catch(NamingException e){
        System.out.println("에러 : " + e.getMessage());
    }catch(SQLException e){
        System.out.println("에러 : " + e.getMessage());
    }finally{
        if(pstmt !=null)pstmt.close();
        if(conn !=null)conn.close();
    }
    
    //성공시 리스트페이지 , 실패시 이전페이지로 이동 자바스크립트
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글수정에 성공했습니다')");
        out.println("location.href='board_list1.jsp?cpage="+cpage+"';");
    }else if(flag==1){
        out.println("alert('비밀번호가 잘못되었습니다.')");
        out.println("history.back();");
    }else{
        out.println("alert('글수정에 실패했습니다')");
        out.println("history.back();");
    }
    out.println("</script>");
    
%>


댓글 없음:

댓글 쓰기