<repString.java>

 


 

package bean;

 

public class repString

{           

             public static String filter( String oldString, String from, String to )

             {

            

                 String newString = oldString;

                 System.out.println(from + " === " + to);

                 int offset = 0; 

                 while( (offset = newString.indexOf( from, offset ))>-1 )

                 {

                     StringBuffer temp = new StringBuffer( newString.substring( 0, offset ) );

                     temp.append( to );

                     temp.append( newString.substring( offset+from.length() ) );

                     newString = temp.toString();

                     offset++;

                 }       

                 System.out.println(newString);

                 return newString;

             }

 

}

 

ÀÌ·¸°Ô ¸¸µé¾îÁø Ŭ·¡½º´Â ´Ù¸¥ Ŭ·¡½º¿¡¼­ ¾µ¼öµµ ÀÖÁö¸¸ ű×Çڵ鷯 Ŭ·¡½º¸¦ ¸¸µç´Ù¸é Ä¿½ºÅÒ Å±׿¡¼­µµ ½±°Ô ¾µ¼ö ÀÖÀ» °Ì´Ï´Ù.

 

<repStringTag.java>

package tag;

 

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

import java.io.*;

import bean.*;

 

public class repStringTag extends BodyTagSupport

{

             String input;

             String replace;

            

             public void setInput(String input){

                           this.input = input;

             }

            

             public void setReplace(String replace){

                           this.replace = replace;

             }

            

             public int doAfterBody(){

                           BodyContent body = getBodyContent();

                           String filteredBody = repString.filter(body.getString(),input,replace);

                           try{

                                        JspWriter out = getPreviousOut();

                                        out.print(filteredBody);

                           }catch(IOException e){

                                        System.out.println("Error :" + e);

                           }

                           return SKIP_BODY;

             }

}

 

´ÙÀ½Àº ÀÌ·¸°Ô ¸¸µé¾îÁø ű×Çڵ鷯¸¦ µî·ÏÇØ ÁÖ¸é µË´Ï´Ù.

 

<taglib_1_0.tld>

 

¡¦¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦¡¦

<tag>

             <name>repString</name>

             <tagclass>tag.repStringTag</tagclass>

             <bodycontent>JSP</bodycontent>

             <info>Replace one character into another</info>

             <attribute>

                           <name>input</name>

                           <required>true</required>

             </attribute>

             <attribute>

                           <name>replace</name>

                           <required>true</required>

             </attribute>

</tag>

¡¦¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦¡¦

 

 

ÀÌÁ¦´Â ¸ðµÎ ¸¸µé¾îÁø ºóÁî¿Í ű×Çڵ鷯¸¦ ½ÇÁ¦·Î JSPÆäÀÌÁö¿¡¼­ ±¸Çö¸¸ ÇÏ¸é µÇ°Ú±º¿ä..

 

¾ÆÂü ±×¸®°í °Ë»ö±â´ÉÀÌ Á¦´ë·Î µ¿ÀÛ Çϵµ·Ï Çϱâ À§ÇØ NoticeList.java ÀÇ getWhere() ¸Þ¼­µå¸¦ Á¶±Ý ¼öÁ¤Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.

 

<NoticeList.java>

¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦

import bean;

 

private String getWhere(){

             String where;

             if(field == null || field.length() == 0){

                           where = "";

             }else{

                           where = "WHERE " + field + " LIKE '%" + repString.filter(key,"'","\'") + "%'";  

             }

             return where;

}

¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦

<view.jsp>

¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦

<tr>

             <td width=100%>

<tl:repString input="\\n" replace="<BR>">

<jsp:getProperty name="notice" property="content"/>

</tl:repString>

             </td>

</tr>

¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦

<%

// Á¶È¸¼ö Áõ°¡ ½ÃÅ°±â

NoticeList.incrCnt(no);

%>

¡¦¡¦¡¦¡¦¡¦

<Áß·«>

¡¦¡¦¡¦¡¦¡¦

 

ÀÌ·¸°Ô Çؼ­ °øÁö»çÇ× ¸¸µå´Â °Í ±îÁö ¾Ë¾Æ º¸¾Ò½À´Ï´Ù.

ÀÇ¿Ü·Î ±ÛÀÌ ±æ¾î Áø °Í »Ó¸¸ ¾Æ´Ï¶ó ³»¿ëÀü´ÞÀÌ Á¦´ë·Î µÇ¾ú´ÂÁöµµ Àß ¸ð¸£°Ú±º¿ä.

°¡´ÉÇÏ¸é ½±°Ô ¼³¸íÇÏ·Á Çߴµ¥ °á±¹ ÀÚ¹ÙÀÚüÀÇ ÀÌÇØ°¡ Çʼö ¿´´ø °Í °°½À´Ï´Ù.

¾ÕÀ¸·Î´Â ÀÚ¹ÙÀÚü¿¡ ´ëÇÑ ³»¿ëÀº TIP & Tech¿¡ °°ÀÌ ¿Ã·ÁµÎµµ·Ï ÇÏ°Ú½À´Ï´Ù.

 



Âü°í ¹®¼­ ¹× »çÀÌÆ®
- ÅÂ±× ¶óÀ̺귯¸® Æ©Å丮¾ó (www.orionsever.com)
- www.webdox.co.kr
- jsp.boolpae.com
- Web Development with JavaServerPages (ÀÎÆ÷ºÏ)
- ¿¹Á¦·Î ¹è¿ì´Â ÀÚ¹Ù ÇÁ·Î±×·¡¹Ö (ÇѺû ¹Ìµð¾î)
- ÆÛÆåÆ® JSP (ÇѺû ¹Ìµð¾î)