<getter / setter ¸Þ¼µå>
// ÀüüÆäÀÌÁö °¹¼ö
public int
getTotalPage(){
return
(int)((total-1)/list_cnt) + 1;
}
// ¸ñ·ÏÀÇ ÆäÀÌÁö ¼³Á¤
public void
setPage(int page){
this.page
= page;
}
// Ãâ·ÂµÉ ¸ñ·ÏÀÇ °¹¼ö ¼³Á¤
public void
setList_cnt(int list_cnt){
this.list_cnt
= list_cnt;
}
// °Ë»öÇÊµå ¼³Á¤
public void
setField(String field){
this.field
= field;
}
// °Ë»ö¾î ¼³Á¤
public void
setKey(String key){
this.key =
key;
}
// Where Àý ¼³Á¤
private String
getWhere(){
String
where;
if(field
== null || field.length() == 0){
where
= "";
}else{
where
= "WHERE " + field + " LIKE '%" + key + "%'";
}
return
where;
}
5. ű×Çڵ鷯 Ŭ·¡½º ÀÛ¼º
¿ì¼± ¾î¶² ÅÂ±× Çڵ鷯 Ŭ·¡½º°¡ ÇÊ¿äÇÑÁö »ý°¢Çغ¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
ÀÌ¹Ì ¸¸µç NoticeList Ŭ·¡½º´Â ¸ñ·ÏÀ» º¤ÅÍ·Î ¸®ÅÏÇÕ´Ï´Ù. ¸®ÅÏµÈ º¤Å͸¦ ·çÇÁ¸¦
µ¹¸é¼ ȸ鿡 °¢ ¿ä¼Òº°·Î Ãâ·Â½ÃÄÑÁִ ű×Çڵ鷯 Ŭ·¡½º°¡ ÇÊ¿äÇÒ °ÍÀÔ´Ï´Ù.
Áö±Ý±îÁö ¿Ã¶ó¿Â °Á³»¿ëÀ» ÄÚµùÇØ º¸½Å ºÐÀ̽öó¸é ¹«¸À» Ä¡½Ã°Ì´Ï´Ù.
±×·¸ÁÒ?? ÀÌ¹Ì ÀÌ Å¬·¡½º´Â IterateTag.java ¿Í
IterateTEI.java ¶ó´Â ÆÄÀÏ·Î ¸¸µå¼ÌÀ» °Ì´Ï´Ù.
ÇϽø¸ ±âÁ¸ÀÇ Å¬·¡½º´Â º¤ÅÍ°¡ ¾Æ´Ñ Ä÷º¼ÇÀ» ó¸®Çϵµ·Ï µÇ¾î ÀÖ½À´Ï´Ù. Ä÷º¼Ç À» º¤ÅÍ·Î
¹Ù²Ù´Â °Ç °£´ÜÇÕ´Ï´Ù.
±×¸®°í, Newline (\n)À» <BR> ű׷Π¹Ù²Ù¾îÁ٠ű׵µ ÀÖÀ¸¸é
ÁÁ°ÚÁÒ?? ÀÌ À¯Æ¿¸®Æ¼ Ŭ·¡½º´Â ±Û³»¿ëÀ»
º¸´Â ºÎºÐÀ» ÀÛ¼ºÇÏ¸é¼ °°ÀÌ ¸¸µé¾î º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
±×·³ ¾î¶² ºÎºÐµéÀÌ ¼öÁ¤µÇ¾î¾ß ÇÏ´ÂÁö »ìÆì º¸ÁÒ..
<IterateTag.java>
¡¦¡¦¡¦
¡¦¡¦¡¦
public class
IterateTag extends BodyTagSupport{
¡¦¡¦¡¦
<Áß·«>
¡¦¡¦¡¦
public
void setVector(Vector vector){
if(vector.size()
> 0){
iterator
= vector.iterator();
}
}
¡¦¡¦¡¦
<Áß·«>
¡¦¡¦¡¦
}
À§ÀÇ º¼µåü·Î Ç¥½ÃµÈ ºÎºÐ¿¡¼ ÀÎÀÚ·Î ¹Þ´Â ºÎºÐ°ú ÀÌ ÀÎÀÚÀÇ µ¥ÀÌÅÍ Å¸ÀÔÀ»
Vector·Î ¹Ù²Ù±â¸¸ ÇÏ¸é µË´Ï´Ù.
´ÙÀ½Àº ű׶óÀ̺귯¸® ½ºÅ©¸³ÅÍ ¿¡¼ ÀÎÀÚ(attribute) ·Î ¼±¾ðµÈ ºÎºÐÁß
collectionÀ¸·Î µÈ ºÎºÐÀ» vector·Î ¹Ù²Ù±â¸¸ ÇÏ¸é µË´Ï´Ù.
< taglib_1_0.tld >
¡¦¡¦¡¦
<Áß·«>
¡¦¡¦¡¦
<tag>
<name>iterate</name>
<tagclass>tag.IterateTag</tagclass>
<teiclass>tag.IterateTEI</teiclass>
<bodycontent>JSP</bodycontent>
<info>A
Simple Iterator</info>
<attribute>
<name>vector</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>true</required>
</attribute>
<attribute>
<name>type</name>
<required>true</required>
</attribute>
</tag>
¡¦¡¦¡¦
<Áß·«>
¡¦¡¦¡¦
ÀÚ ÀÌÁ¤µµ¸é ¸ñ·Ï Ãâ·Â±îÁö´Â ¹®Á¦°¡ ¾øÀ» °Í °°±º¿ä
ÀÌÁ¦ list.jsp ÆäÀÌÁö¸¦ ÀÛ¼ºÇϵµ·Ï ÇÏ°Ú½À´Ï´Ù.
<list.jsp>
<%@ page
contentType="text/html;charset=EUC-KR" %>
<%@ taglib
uri="taglib" prefix="tl"%>
<%
// ÆĶó¹ÌÅÍ·Î
¹Þ´Â °ªÀ» ÃʱâÈÇÏ°í Á¶°Ç¿¡ ¸Âµµ·Ï ¼³Á¤ÇÏ´Â ºÎºÐ
String PAGE =
null;
String field =
null;
String key =
null;
int
current_page;
PAGE =
request.getParameter("PAGE");
field =
request.getParameter("FIELD");
key =
request.getParameter("KEY");
if(PAGE ==
null){
current_page
= 1;
}else{
current_page
= Integer.parseInt(PAGE);
}
if(field !=
null){
key
= new String(key.getBytes("8859_1"),"euc-kr"); // ÇѱÛó¸®
}else{
field
= "";
key
= "";
}
%>
<jsp:useBean
id="NoticeList" class="notice.NoticeList"
scope="request"/>
<jsp:setProperty
name="NoticeList" property="page"
value="<%=current_page%>"/>
<jsp:setProperty
name="NoticeList" property="list_cnt" value="7"/>
<jsp:setProperty
name="NoticeList" property="field"
value="<%=field%>"/>
<jsp:setProperty
name="NoticeList" property="key"
value="<%=key%>"/>
<%
int total =
NoticeList.getTotal();
int total_page
= NoticeList.getTotalPage();
%>
À§ÀÇ ºÎºÐÀº ´ë·« ÀÌÇØ ÇϽǼö ÀÖÀ¸¸®¶ó »ý°¢ÇÕ´Ï´Ù.
¹¹.. Ưº°ÇÑ °Ç ¾øÁÒ..
ÆĶó¹ÌÅÍ·Î ¹Þ´Â °ªµéÀ» ÃʱâÈÇÏ°í ¼³Á¤ÇÏ´Â ºÎºÐ°ú ºóÁî¿¡ ÀÌ °ªÀ» ³Ö¾î¼ ¸ñ·ÏÀ» °¡Á®¿Ã Áغñ¸¦ ÇÏ´Â ºÎºÐ ÀÔ´Ï´Ù.
<jsp:setProperty name="NoticeList"
property="list_cnt" value="7"/>
Àº Ãâ·ÂµÉ ¸ñ·ÏÀÇ °³¼ö¸¦ ¼³Á¤ÇÏ´Â ºÎºÐÀÔ´Ï´Ù. ¿©·¯ºÐÀÇ ÀÔ¸À¿¡ ¸Âµµ·Ï Àû´çÇÑ °ªÀ¸·Î
¼³Á¤ÇÏ½Ã¸é µË´Ï´Ù.
<%
int total = NoticeList.getTotal();
int total_page = NoticeList.getTotalPage();
%>
Àº ¿Ö ÇÊ¿äÇÒ±î¿ä??
óÀ½ ¸»¾¸µå¸°°Íó·³ °øÁö»çÇ׿¡µµ ÆäÀÌ¡ ±¸ÇöÀ» ÇÏ°Ú´Ù°í ¸»¾¸µå·È½À´Ï´Ù.
ÆäÀÌ¡À» ±¸ÇöÇϱâ À§Çؼ´Â Àüü ±ÛÀÇ °³¼ö¿Í ÇÑ ÆäÀÌÁö´ç Ãâ·ÂµÉ ¸ñ·ÏÀÇ °³¼ö ±×¸®°í À̸¦ ¹ÙÅÁÀ¸·Î Àüü ÆäÀÌÁöÀÇ °³¼ö°¡
ÇÊ¿äÇÕ´Ï´Ù.
±×·¡¼ ÀÌ·¯ÇÑ °ªÀ» °è»êÇϱâ À§ÇØ ºóÁî³»¿¡ ¸Þ¼µå¸¦ Ãß°¡ÇÑ°Ì´Ï´Ù.(NoticeList.java
¸¦ Âü°íÇϼ¼¿ä)
±×·³ °è¼ÓÇؼ ¸ñ·ÏÀ» Ãâ·ÂÇÏ´Â ºÎºÐÀ» »ìÆì º¸°Ú½À´Ï´Ù.
¡¦¡¦¡¦¡¦
<Áß·«>
¡¦¡¦¡¦¡¦
<table
width=703 cellpadding=0 cellspacing=0 border=0>
<tr
height=24 align=center>
<td
width=13%>¹ø È£</td>
<td
width=68%>Á¦ ¸ñ</td>
<td
width=13%>ÀÛ ¼º ÀÏ</td>
<td
width=10%>Á¶ ȸ</td>
</TR>
<tl:iterate
name="notice" vector="<%=NoticeList.getList()%>"
type="notice.NoticeRec">
<TR>
<TD
align=center><jsp:getProperty name="notice"
property="num"/></TD>
<TD>
<a
href="view.jsp?PAGE=<%=current_page%>&KEY=<%=key%>&FIELD=<%=field%>&NO=<jsp:getProperty
name="notice" property="no"/>">
<jsp:getProperty
name="notice" property="subject"/>
</a>
</TD>
<TD
align=center><jsp:getProperty name="notice"
property="regi_date"/></TD>
<TD
align=center><jsp:getProperty name="notice"
property="cnt"/></TD>
</TR>
<tr
height=1 align=center><td colspan=4 ></td></tr>
</tl:iterate>
</TABLE>
¡¦¡¦¡¦¡¦
<Áß·«>
¡¦¡¦¡¦¡¦
À§¿¡¼ ´«¿©°Ü º¸½Ç ºÎºÐÀº
<tl:iterate name="notice"
vector="<%=NoticeList.getList()%>"
type="notice.NoticeRec">
ÀÔ´Ï´Ù.
À§ ű״ ¸öü¸¦ ¹Ýº¹ÀûÀ¸·Î ó¸®ÇÏ´Â ÅÂ±× ÀÔ´Ï´Ù.
°¢ ¿ä¼Ò¿¡ ´ëÇÑ Á¢±ÙÀº
<jsp:getProperty name="notice"
property="ÇÁ·ÎÆÛƼ¸í"/>
¿Í °°ÀÌ ÇÏ¸é µË´Ï´Ù.
ÁÖÀÇ ÇÏ½Ç Á¡Àº ¸öü¸¦ ó¸®ÇϹǷΠ</ti:iterate> ¸¦ ¹Ýµå½Ã ½áÁּžß
ÇÕ´Ï´Ù.
ű׿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀº Áö³ °Á¸¦ Âü°íÇϼ¼¿ä..
ű׷Π󸮰¡ µÇ¾î DB Handling ºÎºÐÀÌ ÀüÇô ¾Èº¸ÀÔ´Ï´Ù. °Ô´Ù°¡ while
À̳ª for µîÀÇ ½ºÅ©¸³Æ²¸´µµ ÀüÇô ¾ø±¸¿ä.. ¹Ù·Î Ä¿½ºÅÒ Å±×ÀÇ ÀåÁ¡À̶ó ÇÒ ¼ö ÀÖ½À´Ï´Ù.