본문 바로가기

Study/Programming

JSP 게시판

반응형

board_write1.jsp

<%@ page contentType='text/html;charset=utf-8' %>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=euc-kr'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script language='javascript'>
<!--
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/gi, "");
    }

    function ChkForm(form) {
    }
//-->
</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_write_ok1.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='80' 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='60' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='80' 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='email' size='20' maxlength='50' class='form'>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='passwd' size='10' maxlength='10' class='form'>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='80' 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'><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>


board_write_ok1.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   
<%@ page import="java.sql.*" %>
<%
request.setCharacterEncoding("utf-8");

String subject = request.getParameter("subject");
String writer = request.getParameter("writer");
String email = request.getParameter("email");
String passwd = request.getParameter("passwd");
String content = request.getParameter("content");
String regip = request.getRemoteAddr();

int flag=0;

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
    String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
    String strId = "scott";
    String strPwd = "tiger";
   
    Class.forName("oracle.jdbc.driver.OracleDriver");
   
    conn = DriverManager.getConnection(strUrl, strId, strPwd);
   
    stmt = conn.createStatement();
    String query = "insert into board1 values(bbs1_seq.nextval,'"+subject +"', '"+writer+"','"+email+"', '"+passwd+"', '"+content+"', default, default, '"+regip+"')";
    out.println(query);
    //stmt.executeQuery(query);
           
} catch (ClassNotFoundException e) {
    flag=1;
    System.out.println("드라이버 로드 실패");
} catch (SQLException e){
    flag=2;
    System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
    if(stmt != null) try{ conn.close(); } catch(SQLException e) {}
    if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
    out.println("<script language='javascript'>");   
    if(flag ==0){
        out.println("window.alert('글쓰기 성공하였습니다.')");
        out.println("location.href='board_list1.jsp'");
    }else if(flag ==1){
        out.println("window.alert('드라이버를 로드할 수 없습니다.')");
        out.println("history.bak()");
    }else if(flag ==2){
        out.println("window.alert('SQL 구문이 잘못되었습니다..')");
        out.println("history.bak()");
    }
    out.println("</script>");
%>


board_list1.jsp

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

<%
    request.setCharacterEncoding("utf-8");

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
   
    StringBuffer sb = new StringBuffer();
   
    try {
        String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
        String strId = "scott";
        String strPwd = "tiger";
       
        Class.forName("oracle.jdbc.driver.OracleDriver");
       
        conn = DriverManager.getConnection(strUrl, strId, strPwd);
   
        stmt = conn.createStatement();
        String query = "select seq, subject, writer, regdate, hit from board1 order by seq desc";

        rs = stmt.executeQuery(query);
        while(rs.next()) {
            sb.append("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            sb.append("<tr>");
            sb.append("    <td height='1'></td>");
            sb.append("</tr>");
            sb.append("<tr>");
            sb.append("    <td>");
            sb.append("        <table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            sb.append("        <tr height='25' onMouseOver=\"this.className='evencell'\" onMouseOut=\"this.className=''\">");
            sb.append("            <td width='40' align='center'>" + rs.getInt("seq") + "</td>");
            sb.append("            <td>");
            sb.append("                <span style='width:370' class='elltxt'>");
            sb.append("                    <a href='board_view1.jsp'>" + rs.getString("subject") + "</a>");
            sb.append("                    <img src='../images/ico_n.gif' width='8' height='8' border='0' hspace='3'>");
            sb.append("                </span>");
            sb.append("            </td>");
            sb.append("            <td width='100' align='center'>" + rs.getString("writer") + "</td>");
            sb.append("            <td width='80' align='center'>" + rs.getString("regdate") + "</td>");
            sb.append("            <td width='50' align='center'>" + rs.getInt("hit") + "</td>");
            sb.append("        </tr>");
            sb.append("        </table>");
            sb.append("    </td>");
            sb.append("    </tr>");
            sb.append("<tr>");
            sb.append("<td height='1'></td>");
            sb.append("</tr>");
            sb.append("<tr>");
            sb.append("    <td align='center' class='imgline'></td>");
            sb.append("</tr>");
            sb.append("</table>");
        }
    } catch (ClassNotFoundException e) {
    } catch (SQLException e) {
    } finally {
        if(rs != null) try { rs.close(); } catch(SQLException e) {}
        if(stmt != null) try { stmt.close(); } catch(SQLException e) {}
        if(conn != null) try { conn.close(); } catch(SQLException e) {}
    }
%>
<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>

<!-- 리스트 시작 -->
<%=sb %>
<!-- 리스트 끝 -->

        <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>


board_delete1.jsp

<%@ page contentType='text/html;charset=utf-8' %>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html;charset=euc-kr'>
<link rel='stylesheet' type='text/css' href='../images/common.css'>
<script language='javascript'>
<!--
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/gi, "");
    }

    function ChkForm(form) {
    }
//-->
</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='' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
        <table width='100%' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td width='80' 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='' size='60' class='form' readonly>
            </td>
        </tr>
        <tr>
            <td colspan='2' class='imgline'></td>
        </tr>
        <tr>
            <td width='80' 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='' size='10' maxlength='10' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                메일&nbsp;&nbsp;<input type='text' name='email' value='' size='20' maxlength='70' class='form' readonly>&nbsp;&nbsp;/&nbsp;
                암호&nbsp;&nbsp;<input type='password' name='passwd' 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>



반응형

'Study > Programming' 카테고리의 다른 글

jsp에서 파일 업로드 처리  (0) 2009.06.03
JSP 게시판 공백처리  (0) 2009.06.01
JSP 간단한 게시판  (0) 2009.05.29
JSP Encoder.Decoder  (0) 2009.05.29
JSP 달력  (0) 2009.05.28