* ȸ¿ø°¡ÀÔ * ¾ÆÀ̵ð/ºñ¹Ð¹øÈ£ ã±â   ID PW
Last Modified : 2008.06.28

¸ðµ¨1 °Ô½ÃÆÇ

°Ô½ÃÆÇ Å×À̺í

create table board (
	boardcd varchar2(20),
	boardnm varchar2(40),
	constraint board_boardcd_pk primary key (boardcd)
)
/

create table gul (
	gulno number,
	subject varchar2(100),
	content1 varchar2(4000),
	content2 varchar2(4000),
	content3 varchar2(4000),
	ref number,
	signdate date,
	boardcd varchar2(20),
	constraint gul_gulno_pk primary key (gulno), 
	constraint gul_gulno_fk foreign key (boardcd) references board (boardcd)
)
/

create sequence seq_gul_gulno
start with 1
increment by 1
/

insert into board values ('notice', '°øÁö»çÇ×')
/

°Ô½ÃÆÇ Ŭ·¡½º ¼³°è

OracleConnectionManager °´Ã¼¸¦ À¥ App °¡ ½ÃÀÛµÇ¸é ´Ü Çϳª »ý¼ºµÇ°í À¥App ¿Í ¼ö¸íÀ» °°°Ô Çϱâ À§Çؼ­´Â OracleConnectionManager ¿¡ ½Ì±ÛÅÏ ÆÐÅÏÀ» Àû¿ëÇϰí À¥ App °¡ ·ÎµåµÇ¸é °´Ã¼¸¦ »ý¼ºÇؼ­ ServletContext ¿¡ ÀúÀåÇÏ¸é µÈ´Ù.

OracleConnectionManager.java

package net.java_school.db.dbpool;

public class OracleConnectionManager extends ConnectionManager {
    static private OracleConnectionManager instance = new OracleConnectionManager();
  
    private OracleConnectionManager() {
      super( "oracle" );
      String JDBCDriver = "oracle.jdbc.driver.OracleDriver";
      // ¿À¶óŬ¿ë JDBC thin driver
      String JDBCDriverType = "jdbc:oracle:thin";
      String url = JDBCDriverType + ":@" + dbServer + ":" + port + ":" + dbName;
      connMgr = DBConnectionPoolManager.getInstance();
      connMgr.init( poolName, JDBCDriver, url, userID, passwd, maxConn, initConn, maxWait );
    }
  
    static public OracleConnectionManager getInstance() {
      return instance;
    }
  
}

OracleConnectionManager °´Ã¼°¡ À¥ App °¡ ·ÎµåµÇ¸é »ý¼ºµÇ°í ServletContext ¿¡ ÀúÀåµÇ°Ô Çϱâ À§ÇØ ¾Æ·¡¿Í °°Àº Ŭ·¡½º¸¦ ÀÛ¼ºÇÑ´Ù.

MyServletContextListener.java

package net.java_school.db.dbpool;

import javax.servlet.*;

public class MyServletContextListener implements ServletContextListener {
    public void contextInitialized ( ServletContextEvent event) {
        ServletContext sc = event.getServletContext();
        OracleConnectionManager dbMgr = OracleConnectionManager.getInstance();
        sc.setAttribute("dbMgr", dbMgr);
    }
    
    public void contextDestroyed ( ServletContextEvent event ) {
        ServletContext sc = event.getServletContext();
        sc.removeAttribute("dbMgr");
    }
}

ÀÌ Å¬·¡½º°¡ Á¦ ±â´ÉÀ» ´ÙÇϵµ·Ï ÇÏ·Á¸é web.xml ¿¡ ¾Æ·¡¸¦ web-app ¿¤¸®¸ÕÆ®ÀÇ ÀÚ½Ä ¿¤¸®¸ÕÆ®·Î Ãß°¡ÇÑ´Ù.

web.xml

    <listener>
        <listener-class>net.java_school.db.dbpool.MyServletContextListener</listener-class>
    </listener>

À§ÀÇ Å¬·¡½º ´ÙÀ̾î±×·¥À» º¸¸é¼­ Gul.java, GulDAO.java, GulManager.java ¸¦ ÀÛ¼º
(´ÙÀ̾î±×·¥ÀÌ Á¤È®ÇÏÁö ¾ÊÀ¸´Ï ¾Æ·¡ Äڵ带 º¸°í È®ÀÎ ÇÒ °Í)

Gul.java

package com.dadam.board;

public class Gul {

    private int gulno;
    private String subject;
    private String content;
    private String signdate;
    private int ref;
    private String boardcd;
	
    public int getGulno() {
        return gulno;
    }
    
    public void setGulno(int gulno) {
        this.gulno = gulno;
    }
    
    public String getSubject() {
        return subject;
    }
    
    public void setSubject(String subject) {
        this.subject = subject;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public String getSigndate() {
        return signdate;
    }
    
    public void setSigndate(String signdate) {
        this.signdate = signdate;
    }
    
    public int getRef() {
        return ref;
    }
	
    public void setRef(int ref) {
        this.ref = ref;
    }
    
    public String getBoardcd() {
        return boardcd;
    }
	
    public void setBoardcd(String boardcd) {
        this.boardcd = boardcd;
    }
}

GulDAO.java

package com.dadam.board;

import java.util.*;
import net.java_school.db.dbpool.*;
import java.sql.*;
import net.java_school.util.*;

public class GulDAO {
  
  private OracleConnectionManager dbMgr;

  public GulDAO() {
    dbMgr = OracleConnectionManager.getInstance();
  }

  public ArrayList findGulList ( int cur_page, int num_per_page, String boardcd ) {

    Log log = new Log();
    ArrayList gulList = new ArrayList();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    int start = ( cur_page - 1 ) * num_per_page + 1;
    int end = start + num_per_page - 1;

    String sql = "SELECT gulno,subject,to_char(signdate,'YYYY/MM/DD') signdate,ref FROM " +
        "(" +
        "SELECT ROWNUM R, A.* FROM (select gulno, subject,signdate, ref" +
        "	FROM gul where boardcd = ? ORDER BY gulno DESC) A" +
        ") " +
        "WHERE R BETWEEN ? and ?";

    try {
      con = dbMgr.getConnection();
      pstmt = con.prepareStatement(sql);
      pstmt.setString(1, boardcd);
      pstmt.setInt(2, start);
      pstmt.setInt(3, end);
      rs = pstmt.executeQuery();
      while ( rs.next() ) {
        Gul gul = new Gul();
        gul.setGulno(rs.getInt("gulno"));
        gul.setSubject(rs.getString("subject"));
        gul.setSigndate(rs.getString("signdate"));
        gul.setRef(rs.getInt("ref"));
        gulList.add(gul);
      }
    } catch ( SQLException e ) {
      log.debug( "Error Source:dadam/board/GulDAO.java : SQLException" );
      log.debug( "SQLState : " + e.getSQLState() );
      log.debug( "Message : " + e.getMessage() );
      log.debug( "Oracle Error Code : " + e.getErrorCode() );
      log.debug( "Query : " + sql );
    } finally {
      try {
        if ( rs != null ) rs.close();
        if ( pstmt != null) pstmt.close();
        if ( con != null) dbMgr.freeConnection(con);
        log.close();
      } catch ( SQLException e ) {}
    }

    return gulList;

  }

  public Gul findGul ( int gulno ) {

    Log log = new Log();
    Gul gul = null;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    StringBuffer content = new StringBuffer();
    String sql = "select " +
      "gulno,subject,content1,content2,content3," +
      "to_char(signdate,'YYYY/MM/DD') signdate,ref,boardcd " + 
      "from gul where gulno = ?";
    try {
      con = dbMgr.getConnection();
      pstmt = con.prepareStatement(sql);
      pstmt.setInt(1, gulno);
      rs = pstmt.executeQuery();

      if ( rs.next() ) {
        gul = new Gul();
        gul.setGulno(rs.getInt("gulno"));
        gul.setSubject(rs.getString("subject"));
        String temp = rs.getString("content1");
        if ( temp != null ) content.append(temp);
        temp = rs.getString("content2");
        if ( temp != null ) content.append(temp);
        temp = rs.getString("content3");
        if ( temp != null ) content.append(temp);
        gul.setContent(content.toString());
        gul.setSigndate(rs.getString("signdate"));
        gul.setRef(rs.getInt("ref"));
        gul.setBoardcd(rs.getString("boardcd"));
      }
    } catch ( SQLException e ) {
      log.debug( "Error Source:dadam/board/GulDAO.java : SQLException" );
      log.debug( "SQLState : " + e.getSQLState() );
      log.debug( "Message : " + e.getMessage() );
      log.debug( "Oracle Error Code : " + e.getErrorCode() );
      log.debug( "Query : " + sql );
    } finally {
      try {
        if ( rs != null ) rs.close();
        if ( pstmt != null) pstmt.close();
      } catch ( SQLException e ) {}
      if ( con != null) dbMgr.freeConnection(con);
      log.close();
    }

    return gul;
  }

  public int create ( Gul gul ) {

    Log log = new Log();
    int success = 0;
    String content1 = gul.getContent();
    String content2 = "";
    String content3 = "";
    String content = gul.getContent();
    if ( content.length() <= 6000 ) { 
      if ( content.length() > 2000 && content.length() <= 4000 ) {
        content1 = content.substring(0, 2000);
        content2 = content.substring(2000, content.length());
      } else if ( content.length() > 4000 && content.length() <= 6000 ) {
        content1 = content.substring(0, 2000);
        content2 = content.substring(2000, 4000);
        content3 = content.substring(4000, content.length());
      }

      String sql = "insert into gul " +
      "(gulno, subject, content1, content2, content3, ref, signdate, boardcd ) " + 
      " values (seq_gul_gulno.nextval, ?, ?, ?, ?, 0, sysdate, ?)";

      Connection con = null;
      PreparedStatement pstmt = null;

      try {
        con = dbMgr.getConnection();
        pstmt = con.prepareStatement(sql);
        pstmt.setString(1, gul.getSubject());
        pstmt.setString(2, content1);
        pstmt.setString(3, content2);
        pstmt.setString(4, content3);
        pstmt.setString(5, gul.getBoardcd());
        success = pstmt.executeUpdate();
      } catch ( SQLException e ) {
        log.debug( "Error Source:dadam/board/write_proc.jsp : SQLException" );
        log.debug( "SQLState : " + e.getSQLState() );
        log.debug( "Message : " + e.getMessage() );
        log.debug( "Oracle Error Code : " + e.getErrorCode() );
        log.debug( "Query : " + sql );
      } finally {
        try {
          if ( pstmt != null) pstmt.close();
        } catch ( SQLException e ) {}	
        if ( con != null) dbMgr.freeConnection(con);
        log.close();
      }
    }

    return success;
  }

  public int update ( Gul gul ) {

    Log log = new Log();
    int success = 0;

    String content1 = gul.getContent();
    String content2 = "";
    String content3 = "";

    String content = gul.getContent();
    if ( content.length() <= 6000 ) { 
      if ( content.length() > 2000 && content.length() <= 4000 ) {
        content1 = content.substring(0, 2000);
        content2 = content.substring(2000, content.length());
      } else if ( content.length() > 4000 && content.length() <= 6000 ) {
        content1 = content.substring(0, 2000);
        content2 = content.substring(2000, 4000);
        content3 = content.substring(4000, content.length());
      }

      String sql = "update gul set subject = ?," +
      "content1 = ?," +
      "content2 = ?," +
      "content3 = ? " +
      "where gulno = ?";
      Connection con = null;
      PreparedStatement pstmt = null;

      try {
        con = dbMgr.getConnection();
        pstmt = con.prepareStatement(sql);
        pstmt.setString(1, gul.getSubject());
        pstmt.setString(2, content1);
        pstmt.setString(3, content2);
        pstmt.setString(4, content3);
        pstmt.setInt(5, gul.getGulno());
        success = pstmt.executeUpdate();
      } catch ( SQLException e ) {
        log.debug( "Error Source:dadam/board/modify_form.jsp : SQLException" );
        log.debug( "SQLState : " + e.getSQLState() );
        log.debug( "Message : " + e.getMessage() );
        log.debug( "Oracle Error Code : " + e.getErrorCode() );
        log.debug( "Query : " + sql );
      } finally {
        try {
          if ( pstmt != null) pstmt.close();
        } catch ( SQLException e) {}
        if ( con != null) dbMgr.freeConnection(con);
        log.close();
      }
    }
    return success;
  }

  public int remove ( int gulno ) {
    Log log = new Log();
    int success = 0;
    String sql = "delete from gul where gulno = ? ";

    Connection con = null;
    PreparedStatement pstmt = null;

    try {
      con = dbMgr.getConnection();
      pstmt = con.prepareStatement(sql);
      pstmt.setInt(1, gulno);
      success = pstmt.executeUpdate();
    } catch ( SQLException e ) {
      log.debug( "Error Source:dadam/board/delete_proc.jsp : SQLException" );
      log.debug( "SQLState : " + e.getSQLState() );
      log.debug( "Message : " + e.getMessage() );
      log.debug( "Oracle Error Code : " + e.getErrorCode() );
      log.debug( "Query : " + sql );
    } finally {
      try {
        if ( pstmt != null) pstmt.close();
      } catch ( SQLException e) {}	
      if ( con != null) dbMgr.freeConnection(con);
      log.close();
    }

    return success;
  }

  public int updateRef ( int gulno ) {
    Log log = new Log();
    int success = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    // ¸ÕÀú ref ¸¦ 1 Áõ°¡½ÃŰ´Â Äõ¸®¸¦ ½ÇÇàÇÑ´Ù.
    String sql = "update gul set ref = ref + 1 where gulno = ?";
    try {
      con = dbMgr.getConnection();
      pstmt = con.prepareStatement(sql);
      pstmt.setInt(1, gulno);
      success = pstmt.executeUpdate();
    } catch ( SQLException e ) {
      log.debug( "Error Source:dadam/board/GulDAO.java : SQLException" );
      log.debug( "SQLState : " + e.getSQLState() );
      log.debug( "Message : " + e.getMessage() );
      log.debug( "Oracle Error Code : " + e.getErrorCode() );
      log.debug( "Query : " + sql );
    } finally {
      try {
        if ( pstmt != null) pstmt.close();
      } catch ( SQLException e) {}	
      if ( con != null) dbMgr.freeConnection(con);
      log.close();
    }

    return success;
  
  }

  public int getTotalRecord ( String boardcd ) {
    Log log = new Log();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    String sql = "select count(*) from gul where boardcd = ? ";
    int total_record = 0;
    try {
      con = dbMgr.getConnection();
      pstmt = con.prepareStatement(sql);
      pstmt.setString(1, boardcd);
      rs = pstmt.executeQuery();
      rs.next();
      total_record = rs.getInt(1);
    } catch ( SQLException e ) {
      log.debug( "Error Source:dadam/board/list.jsp : SQLException" );
      log.debug( "SQLState : " + e.getSQLState() );
      log.debug( "Message : " + e.getMessage() );
      log.debug( "Oracle Error Code : " + e.getErrorCode() );
      log.debug( "Query : " + sql );
    } finally {
      try {
        if ( rs != null ) rs.close();
        if ( pstmt != null) pstmt.close();
        if ( con != null) dbMgr.freeConnection(con);
        log.close();
      } catch ( SQLException e ) {}
    }

    return total_record;

  }
}

GulManager.java

package com.dadam.board;

import java.util.ArrayList;
import java.util.List;

public class GulManager {
	
    private GulDAO gulDAO = new GulDAO();
	
    public ArrayList findGulList( int cur_page, int num_per_page, String boardcd ) {
        return gulDAO.findGulList(cur_page, num_per_page, boardcd);
    }
	
    public Gul findGul ( int gulno ) {
        return gulDAO.findGul(gulno);
    }
	
    public int create ( Gul gul ) {
        return gulDAO.create(gul);
    }
	
    public int update ( Gul gul ) {
        return gulDAO.update(gul);
    }

    public int remove ( int gulno ) {
        return gulDAO.remove(gulno);
    }
	
    public int updateRef ( int gulno ) {
        return gulDAO.updateRef(gulno);
    }

    public int getTotalRecord ( String boardcd ) {
        return gulDAO.getTotalRecord(boardcd);
    }
}

list.jsp, view.jsp, modify_form.jsp, modify_proc.jsp, delete_proc.jsp, write_proc.jsp ¼øÀ¸·Î ÆäÀÌÁö¸¦ ¼öÁ¤

list.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR" 
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="net.java_school.util.Log" %>
<%@ page import="com.dadam.board.*" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" 
scope="request" />
<%
  Log log = new Log();

  // Parameter
  int cur_page = (request.getParameter("cur_page") == null) ? 1 :	
  Integer.parseInt(request.getParameter("cur_page"));
  String board = request.getParameter("board");
  if ( board == null ) {
    board = "notice";
  }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitonal.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>¸ðµ¨1 °Ô½ÃÆÇ</title>
<script language="javascript">

  function goWrite() {
    var form = document.getElementById("frmWrite");
    form.submit();
  }

  function goView(number) {
    var form = document.getElementById("frmView");
    form.number.value = number;
    form.submit();
  }

  function goList(cpage) {
    var form = document.getElementById("frmList");
    form.cur_page.value = cpage;
    form.submit();
  }

</script>
</head>
<body>
  <table border="1">
  <tr>
    <th>P.K</th>
    <th>Á¦¸ñ</th>
    <th>µî·ÏÀÏ</th>
    <th>Á¶È¸</th>
  </tr>	
<%
  int num_per_page = 7;
  ArrayList gulList = gulManager.findGulList( cur_page, num_per_page, board );
  for ( int i = 0; i < gulList.size(); i++ )  {
    Gul gul = (Gul)gulList.get(i);	
%>
  <tr>
    <td><%=gul.getGulno()%></td>
    <td>
      <a href="javascript:goView('<%=gul.getGulno() %>')"><%=gul.getSubject()%></a>
    </td>
    <td><%=gul.getSigndate()%></td>
    <td><%=gul.getRef()%></td>
  </tr>
<%
 }
%>
  </table>
  <p>
  <input type="button" value="»õ±Û" onclick="javascript:goWrite('<%=board %>')" />
  </p>
  <p>
<%

  int total_record = 	gulManager.getTotalRecord(board);

  int total_page = 0; // ÃʱâÈ­
  if ( total_record != 0 ) {
    if ( ( total_record % num_per_page ) == 0 ) {
      total_page = total_record / num_per_page;
    } else {
      total_page = total_record / num_per_page + 1;
    }	
  }

  // ÆäÀÌÁö Á÷Á¢ À̵¿ ¸µÅ© Á¦ÇÑ ÄÚµå ½ÃÀÛ
  int block = 1;
  int page_per_block = 6;
  if ( (cur_page % page_per_block ) == 0 ) {
    block = cur_page / page_per_block;
  } else {
    block = cur_page / page_per_block + 1;
  }

  int first_page = ( block - 1 ) * page_per_block + 1;
  int last_page = block * page_per_block;

  int total_block = 1;
  if ( ( total_page % page_per_block ) == 0 ) { 
    total_block = total_page / page_per_block; 
  } else {
    total_block = total_page / page_per_block + 1;
  }

  if ( block >= total_block ) {
    last_page = total_page;
  }

  if ( block > 1 ) {
    int prev_page = first_page - 1;
%>
  <a href="javascript:goList('<%=prev_page %>')">[ÀÌÀü]</a>
<%
  }
  for ( int i = first_page; i <= last_page; i++) {
%>
  <a href="javascript:goList('<%=i%>')">[<%=i%>]</a>
<%
  }
  if ( block < total_block ) {
    int next_page = last_page + 1;	
%>
  <a href="javascript:goList('<%=next_page %>')">[´ÙÀ½]</a>
<%
  }
%>	
  </p>
  <div id="form-grp">
    <form id="frmList" name="frmList" action="list.jsp" method="post">
      <input type="hidden" name="board" value="<%=board %>" />
      <input type="hidden" name="cur_page" />
    </form>
    <form id="frmView" name="frmView" action="view.jsp" method="post">
      <input type="hidden" name="number" />
      <input type="hidden" name="board" value="<%=board %>" />
      <input type="hidden" name="cur_page" value="<%=cur_page %>" />
    </form>
    <form id="frmWrite" name="frmWrite" action="write_form.jsp" method="post">
      <input type="hidden" name="board" value="<%=board %>" />
      <input type="hidden" name="cur_page" value="<%=cur_page %>" />
    </form>
  </div>
</body>
</html>

view.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
  pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.java_school.util.Log" %>
<%@ page import="com.dadam.board.*" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" 
scope="request" />
<%
  int number = Integer.parseInt(request.getParameter("number"));
  String board = request.getParameter("board");
  String cur_page = request.getParameter("cur_page");

  gulManager.updateRef(number);
  Gul gul = gulManager.findGul(number);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitonal.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>¸ðµ¨1 °Ô½ÃÆÇ</title>
<link rel="stylesheet" href="..css/screen.css" type="text/css" media="screen" />
<script language="javascript">

  function goDelete() {
    var chk = confirm('Á¤¸»·Î »èÁ¦ÇϽðڽÀ´Ï±î?');
    if(chk) {
      var form = document.getElementById("frmDelete");
      form.submit();
    }
  }

  function goList() {
    var form = document.getElementById("frmList");
    form.submit();
  }

  function goModify() {
    var form = document.getElementById("frmModify");
    form.submit();
  }

  function goDelete() {
    var chk = confirm('Á¤¸»·Î »èÁ¦ÇϽðڽÀ´Ï±î?');
    if ( chk ) {
      var form = document.getElementById("frmDelete");
      form.submit();
    }
  }
	
</script>
</head>
<body>
<p>
  Á¦¸ñ : <%=gul.getSubject() %><br />
  µî·ÏÀÏ : <%=gul.getSigndate() %><br />
  Á¶È¸¼ö : <%=gul.getRef() %><br />
  º»¹® : <br /><%=gul.getContent().replaceAll("\n", "<br />") %>
</p>
<p>
  <input type="button" value="¸ñ·Ï" onclick="javascript:goList()" />
  <input type="button" value="¼öÁ¤" onclick="javascript:goModify()" />
  <input type="button" value="»èÁ¦" onclick="javascript:goDelete()" />
</p>
<div id="form-grp">
  <form id="frmList" name="frmList" action="list.jsp" method="post">
    <input type="hidden" name="board" value="<%=board %>" />
    <input type="hidden" name="cur_page" value="<%=cur_page %>" />
  </form>
  <form id="frmModify" name="frmModify" action="modify_form.jsp" method="post">
    <input type="hidden" name="number" value="<%=number %>" />
    <input type="hidden" name="board" value="<%=board %>" />
    <input type="hidden" name="cur_page" value="<%=cur_page %>" />
  </form>
  <form id="frmDelete" name="frmDelete" action="delete_proc.jsp" method="post">
    <input type="hidden" name="number" value="<%=number %>" />
    <input type="hidden" name="board" value="<%=board %>" />
    <input type="hidden" name="cur_page" value="<%=cur_page %>" />
  </form>
</div>
</body>
</html>

write_form.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
  pageEncoding="EUC-KR"%>
<%
  String board = request.getParameter("board");
  String cur_page = request.getParameter("cur_page");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitonal.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
  <title>Insert title here</title>
  <script language="javascript">
  function checking() {
    var form = document.getElementById("frmWrite");
    if ( form.subject.value.length == 0) {
      alert("Á¦¸ñÀ» ÀÔ·ÂÇϼ¼¿ä");
      form.subject.focus();
      return;
    }
    if ( form.content.value == '') {
      alert("º»¹®À» ÀÔ·ÂÇϼ¼¿ä");
      form.content.focus();
      return;
    } else {
      if ( form.content.value.length > 6000 ) {
        alert("6000ÀÚ ÀÌ»óÀº ÀÔ·ÂÇÒ ¼ö ¾ø½À´Ï´Ù.!");
        return;
      }
    }
    form.submit();
  }

  function goList() {
    var form = document.getElementById("frmList");
    form.submit();
  }

  </script>
</head>
<body>
  <form id="frmWrite" name="frmWrite" action="write_proc.jsp" method="post">
    <input type="hidden" name="boardcd" value="<%=board %>" />
    Á¦¸ñ : <input type="text" name="subject" /><br />
    º»¹® : <br />
    <textarea name="content" cols="30" rows="10"></textarea><br />
    <input type="button" value="Àü¼Û" onclick="javascript:checking()" />
    <input type="button" value="¸ñ·Ï" onclick="javascript:goList()" />
  </form>
  <form id="frmList" name="frmList" action="list.jsp" method="post">
    <input type="hidden" name="boardcd" value="<%=board %>" />
    <input type="hidden" name="cur_page" value="<%=cur_page %>" />
  </form>
</body></html>

modify_form.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.java_school.util.Log" %>
<%@ page import="com.dadam.board.*" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" 
scope="request" />
<%
  String board = request.getParameter("board");
  String cur_page = request.getParameter("cur_page");
  int number = Integer.parseInt(request.getParameter("number"));
  Gul gul = gulManager.findGul(number);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitonal.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>¸ðµ¨ 1 °Ô½ÃÆÇ</title>
<link rel="stylesheet" href="..css/screen.css" type="text/css" media="screen" />
<script language="javascript">
  
  function checking() {
    var form = document.getElementById("frmWrite");
    if ( form.subject.value.length == 0) {
      alert("Á¦¸ñÀ» ÀÔ·ÂÇϼ¼¿ä");
      form.subject.focus();
      return;
    }
    if ( form.content.value == '') {
      alert("º»¹®À» ÀÔ·ÂÇϼ¼¿ä");
      form.content.focus();
      return;
    } else {
      if ( form.content.value.length > 6000 ) {
        alert("6000ÀÚ ÀÌ»óÀº ÀÔ·ÂÇÒ ¼ö ¾ø½À´Ï´Ù.!");
        return;
      }
    }
    form.submit();
  }

  function goView() {
    var form = document.getElementById("frmView");
    form.submit();
  }

</script>
</head>
<body>
  <form id="frmWrite" name="frmWrite" action="modify_proc.jsp" method="post">
    <input type="hidden" name="number" value="<%=number %>" />
    <input type="hidden" name="board" value="<%=board %>" />
    <input type="hidden" name="cur_page" value="<%=cur_page %>" />
    Á¦¸ñ : <input type="text" name="subject" value="<%=gul.getSubject() %>" /><br />
    º»¹® : <br />
    <textarea name="content" cols="30" rows="10"><%=gul.getContent() %></textarea><br />
    <input type="button" value="Àü¼Û" onclick="javascript:checking()" />
    <input type="button" value="»ó¼¼º¸±â" onclick="javascript:goView()" />
  </form>
  <div id="form-grp">
    <form id="frmView" name="frmView" action="view.jsp" method="post">
      <input type="hidden" name="number" value="<%=number %>" />
      <input type="hidden" name="board" value="<%=board %>" />
      <input type="hidden" name="cur_page" value="<%=cur_page %>" />
    </form>
  </div>	
</body>
</html>

modify_proc.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.java_school.util.Log" %>
<%@ page import="com.dadam.board.*" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" 
scope="request" />
<%
  Log log = new Log();
  // parameter 
  request.setCharacterEncoding("euc-kr");
  String board = request.getParameter("board"); 
  String cur_page = request.getParameter("cur_page"); 
  int number = Integer.parseInt(request.getParameter("number"));
  String subject = request.getParameter("subject");
  String content = request.getParameter("content");

  Gul gul = new Gul();
  gul.setGulno(number);
  gul.setSubject(subject);
  gul.setContent(content);
  int success = gulManager.update(gul);
  if ( success > 0 ) {
    String url = "view.jsp?board=" + board + "&number=" + number + "&cur_page=" + cur_page;
    response.sendRedirect(url);
  } else {
%>		
  <script language='javascript'>
    alert('º»¹®ÀÌ ³Ê¹« ±é´Ï´Ù.');
    history.go(-1);
  </script>
<%
  } 
%>

delete_proc.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.java_school.util.Log" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" scope="request" />
<%
  // parameter
  String board = request.getParameter("board");
  String cur_page = request.getParameter("cur_page"); 
  int number = Integer.parseInt(request.getParameter("number"));
  int success = gulManager.remove(number);
  response.sendRedirect("list.jsp?board=" + board + "&cur_page=" + cur_page);	
%>

write_proc.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.java_school.util.Log" %>
<%@ page import="com.dadam.board.*" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" 
scope="request" />
<%
  // parameter 
  request.setCharacterEncoding("euc-kr");
  String board = request.getParameter("board");
  String subject = request.getParameter("subject");
  String content = request.getParameter("content");

  Gul gul = new Gul();
  gul.setSubject(subject);
  gul.setContent(content);
  gul.setBoardcd(board);

  int success = gulManager.create(gul);
  if( success > 0 ) {
    response.sendRedirect("list.jsp?board=" + board);
  } else {
%>		
  <script language='javascript'>
    alert('º»¹®ÀÌ ³Ê¹« ±é´Ï´Ù.');
    history.go(-1);
  </script>
<%
  } 
%>

write_proc.jsp ¸¦ <jsp:setProperty .. ¾×¼ÇÀ» ÀÌ¿ëÇÏ¿© ¼öÁ¤

write_proc.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
  pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.java_school.util.Log" %>
<%@ page import="com.dadam.board.*" %>
<jsp:useBean id="gulManager" class="com.dadam.board.GulManager" scope="request" />
<jsp:useBean id="gul" class="com.dadam.board.Gul" scope="request" />
<%
  request.setCharacterEncoding("euc-kr"); // Çѱ۶§¹®¿¡ jsp:setProperty ÀÌÀü¿¡ À§Ä¡
%>
<jsp:setProperty name="gul" property="*"/>
<%
  int success = gulManager.create(gul);
  if( success > 0 ) {
    response.sendRedirect("list.jsp?board=" + gul.getBoardcd());
  } else {
%>		
  <script language='javascript'>
    alert('º»¹®ÀÌ ³Ê¹« ±é´Ï´Ù.');
    history.go(-1);
  </script>
<%
  } 
%>