4. ±Û ³»¿ëÀ» º¸±â À§ÇÑ Å¬·¡½º Á¤ÀÇ(Board.java)

ÇØ´ç±ÛÀ» º¸±âÀ§Çؼ­´Â ±ÛÀÇ À妽º¹øÈ£¸¦ ³Ñ°ÜÁÖ¸é µË´Ï´Ù.

¹°·Ð »ç¿ëÀÚ°¡ ¾î¶² °æ·Î·Î À̵¿Çß´ÂÁö ¾Ë±âÀ§Çؼ­´Â ÆäÀÌÁö°ªÀ̳ª °Ë»ö¾î,°Ë»öÇʵ嵵 ¾Ë°í ÀÖ´Ù¸é ´Ù½Ã ¸ñ·ÏÀ¸·Î À̵¿ÇÒ°æ¿ì Æí¸®ÇÏ°Ô ÀÌ¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.

¿©±â¼­´Â ±Û ³»¿ëÀ» °¡Á®¿À±â À§ÇÑ ¸Þ¼­µå¸¦ »ìÆ캸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

 

Board.java

public Vector getArticle(int no) throws SQLException{

    Connection con = null;

    Statement stmt = null;

    ResultSet rs = null;

 

    Vector v = new Vector();

    String query;

    int cnt;

 

    try{

      BoardRec br = new BoardRec();

      con = getDBConnection();

      stmt = con.createStatement();

      query = "SELECT NAME,EMAIL,SUBJECT,CONTENT,REGI_DATE,CNT,PASSWD FROM BOARD_T WHERE NO = " + no ;

 

      rs = stmt.executeQuery(query);

      rs.next();

      br.name = rs.getString("NAME");

      br.email = rs.getString("EMAIL");

      br.subject = rs.getString("SUBJECT");

      br.content = rs.getString("CONTENT");

      br.regi_date = rs.getString("REGI_DATE");

               br.passwd = rs.getString("PASSWD");

      br.cnt = rs.getInt("CNT");

 

      v.addElement(br);

    }catch(SQLException e){

      e.getMessage();

    }finally{

      if(rs != null) rs.close();

      if(stmt != null) stmt.close();

      if(con != null) con.close();

    }

    return v;

  }

±Û¸ñ·ÏÀ» Ãâ·ÂÇϱâ À§ÇÑ ¸Þ¼­µå¿Í Å©°Ô ´Ù¸¥ Á¡Àº ¾ø½À´Ï´Ù.

´ÜÁö À妽º °ªÀ» ¹Þ¾Æ ¿À°í ÀÌ °ª¿¡ ÇØ´çÇÏ´Â ±Û¸¸ º¤ÅÍ·Î ³Ñ°Ü ÁÖ´Â Á¡ÀÌ ´Ù¸¦ »ÓÀÌÁÒ..

JSP ÆäÀÌÁö¿¡¼­´Â ¾î¶»°Ô ±¸ÇöÀÌ µÇ´ÂÁö »ìÆ캸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

view.jsp

<tl:iterate name="view" vector="<%=list.getArticle(no)%>" type="board.BoardRec">

<table width=703 cellpadding=0 cellspacing=0 border=0>

<tr height=25 bgcolor="#f2f2f2">

    <td &nbsp;&nbsp;<b><jsp:getProperty name="view" property="subject"/></b></td>

</tr>

<tr height=25 bgcolor="#f2f2f2" align=center>

<td width=110>ÀÛ ¼º ÀÚ</td>

<td width=120>

             <a href="mailto:<jsp:getProperty name="view" property="email"/>">

             <jsp:getProperty name="view" property="name"/>

             </a>

      </td>

      <td width=110>ÀÛ ¼º ÀÏ</td>

      <td width=140><jsp:getProperty name="view" property="regi_date"/></td>

      <td width=110>Á¶ ȸ ¼ö</td>

      <td width=108><jsp:getProperty name="view" property="cnt"/></td>

  </tr>

<tr height=25>

    <td colspan=11>

      <table width=703 cellpadding=10 cellspacing=0 border=0>

      <tr>

                           <td width=100%>

                           <%

                                        out.println(repString.filter(view.content,"\n","<br>"));

                           %>

                           </td>

      </tr>

      </table>

    </td>

  </tr>

  <tr height=1 bgcolor="#afafaf">

    <td colspan=11><img src="img/clear.gif" height=1 width=1></td>

  </tr>

</table>

</tl:iterate>

Iterate ű׸¦ °è¼ÓÇؼ­ »ç¿ëÇÏ°í ÀÖ±º¿ä.

°Ô´Ù°¡ À¯Æ¿¸®Æ¼ ¸Þ¼­µåÀÎ repString Ŭ·¡½ºµµ ¾²°í ÀÖ½À´Ï´Ù.

»ç½Ç °ü·Ã±Û ¸ñ·Ï Ãâ·ÂÀº ´õ¿í °£´ÜÇÕ´Ï´Ù.

ÀÌ¹Ì ¸®½ºÆ® Ãâ·Â¿¡¼­ »ç¿ëµÇ¾ú´ø ¹æ¹ýÀ» ±×´ë·Î ÀÌ¿ëÇÏ¸é µË´Ï´Ù.

´ÜÁö.. °ü·Ã±Û¸¸ °¡Á®¿À´Â ¸Þ¼­µå¸¸ Ãß°¡ ÇÏ¸é µÇ±¸¿ä.

Board.java

public Vector getThread(int group) throws SQLException{

 

    Connection con = null;

    Statement stmt = null;

    ResultSet rs = null;

 

    Vector v = new Vector();

    String query ;

 

    try{

      con = getDBConnection();

      stmt = con.createStatement();

query="SELECT ¡° +

¡°NO,NAME,EMAIL,SUBJECT,CONTENT,REGI_DATE,CNT,GROUP_ID,¡± +

¡°GROUP_ORDER,DEPTH " +

                "FROM BOARD_T ¡° +

¡°WHERE GROUP_ID=" + group + " ORDER BY GROUP_ORDER ASC";

      rs = stmt.executeQuery(query);

 

      while(rs.next()){

             BoardRec br = new BoardRec();

             br.no = rs.getInt("NO");

             br.name = rs.getString("NAME");

             br.email = rs.getString("EMAIL");

             br.subject = rs.getString("SUBJECT");

             br.content = rs.getString("CONTENT");

             br.regi_date = rs.getString("REGI_DATE");

             br.cnt = rs.getInt("CNT");

             br.group_id = rs.getInt("GROUP_ID");

             br.group_order = rs.getInt("GROUP_ORDER");

             br.depth = rs.getInt("DEPTH");

             v.addElement(br);

      }

     }catch(SQLException e){

       throw new SQLException(e.getMessage());

     }finally{

             if (rs != null) rs.close();

             if (stmt != null) stmt.close();

             if (con != null) con.close();

     }

     return v;

  }

¸ñ·ÏÀ» °¡Á®¿À´Â ¸Þ¼­µå³ª ÇØ´ç±ÛÀÇ ³»¿ë¸¸ °¡Á®¿À´Â ¸Þ¼­µå¿Í º° ´Ù¸¦ °ÍÀÌ ¾ø½À´Ï´Ù.

±×·¸´Ù¸é JSP ÆäÀÌÁöµµ ¿ª½Ã ¶È °°°ÚÁÒ??

view.jsp

<tl:iterate name="Thread" vector="<%=list.getThread(group_id)%>" type="board.BoardRec">

  <tr height=24 align=center>

    <td align=left>

                           <%

                           String re = "";

                           if(Thread.depth >= 1){

                                        re = "<img src=img/icon_re.gif>";

                           }

                           for(int i=0;i<=Thread.depth;i++){

                                        out.println("&nbsp;&nbsp;");

                           }

                           %>

                           <%=re%>            

      <a href="view.jsp?KEY=<%=key%>&FIELD=<%=field%>&PAGE=<%=PAGE%>&NO=<jsp:getProperty name="Thread" property="no"/>">

      <jsp:getProperty name="Thread" property="subject"/>

      </a>

    </td>

    <td>

      <a href="mailto:<jsp:getProperty name="Thread" property="email"/>">

      <jsp:getProperty name="Thread" property="name"/>

      </a>

    </td>

    <td><jsp:getProperty name="Thread" property="regi_date"/></td>

    <td><jsp:getProperty name="Thread" property="cnt"/></td>

  </tr>

  <tr height=1 align=center><td colspan=4 background="img/back_verdot2.gif"></td></tr>

</tl:iterate>

 

»ç½Ç ¿©±â¼­ ¼³¸íµÇÁö ¾ÊÀº ºÎºÐÀÌ ÀÖ½À´Ï´Ù. ¿¹¸¦µé¾î Á¶È¸¼öÁõ°¡³ª ¸ñ·ÏÀ¸·Î °¡±â À§ÇÑ ¸µÅ© 󸮵îÀÌ ±×°ÍÀÌ ÀÔ´Ï´Ù. À̺κÐÀº Á÷Á¢ ¼Ò½º¸¦ º¸½Ã°í ³ª¸§´ë·Î ¿¬±¸ÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù(¾î·ÆÁö ¾Ê½À´Ï´Ù. Àý´ë·Î).

 

2003-07-27