• ÇÁ¸®Ä«¿îÅÍ
  • Ç÷¡½ÃºÏ
  • ÇÁ¸®º¸µå
  • Àü±¤ÆÇ
  • À¥°øºÎ¹æ
  • Ä¿¹Â´ÏƼ
[java] util tip 2008.05.13 10:04
±Û¾´ÀÌ : ¿î¿µÀÚ Á¶È¸ : 1976 Ãßõ : 0

* String À» English¿¡¼­ Korean charsetÀ¸·Î µðÄÚµù
   new String(str.getBytes("8859_1"), "KSC5601");
   new String(str.getBytes("8859_1"), "euc-kr")

 
 
 
 
package audit.common;
import java.text.*;
import java.util.*;
import java.rmi.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
public class Utility extends SysDate
{
    private static Utility instance = null;
    private Properties p;
    private boolean bKoreanToEnglish;
    private boolean jspKoreanToEnglish;
    public Utility()
    {}
    /** ¹®ÀÚ¿­ÀÇ ¿À¸¥ÂÊÀÇ ½ºÆäÀ̽º¸¦ ¾ø¾Ö¼­ ¹®ÀÚ¿­À» ¸®ÅÏÇÑ´Ù.
     *   @param  s ´ë»ó¹®ÀÚ¿­
     *   @return °ø¹éÀ» ¾ø¾Ø ¹®ÀÚ¿­
     */
    public String rTrim(String s)
    {
        String sRtn = null;
        String sChar = null;
        int iLen = s.length();
        for (int i = 0; i < iLen; i++)
        {
            sChar = s.substring(i, i + 1);
            if (sChar.equals(" "))
            {
                sRtn = s.substring(i + 1, iLen);
            }
            else
            {
                break;
            }
        }
        return sRtn;
    }
    /** ¹®ÀÚ¿­ÀÇ ¿ÞÂÊÀÇ ½ºÆäÀ̽º¸¦ ¾ø¾Ö¼­ ¹®ÀÚ¿­À» ¸®ÅÏÇÑ´Ù.
     *   @param  s ´ë»ó¹®ÀÚ¿­
     *   @return  °ø¹éÀ» ¾ø¾Ø ¹®ÀÚ¿­
     */
    public String lTrim(String s)
    {
        return "";
    }
    /** ¹®ÀÚ¿­ ³»ºÎÀÇ ½ºÆäÀ̽º¸¦ ¾ø¾Ö¼­ ¹®ÀÚ¿­À» ¸®ÅÏÇÑ´Ù.
     *   @param  s ´ë»ó¹®ÀÚ¿­
     *   @return  °ø¹éÀ» ¾ø¾Ø ¹®ÀÚ¿­
     */
    public String mTrim(String s)
    {
        String sRtn = null;
        sRtn = s.trim();
        return sRtn;
    }
    /**
     * ±Ý¾×¹®ÀÚ¿­À» ±Ý¾×Ç¥½ÃŸÀÔÀ¸·Î º¯È¯ÇÑ´Ù. <BR>
     * (¿¹) 12345678 --> 12,345,678          <BR>
     * @param    moneyString ±Ý¾×¹®ÀÚ¿­.
     * @return   ±Ý¾×.
     */
    public String makeMoneyType(String moneyString)
    {
        DecimalFormat df = new DecimalFormat();
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setGroupingSeparator(',');
        df.setGroupingSize(3);
        df.setDecimalFormatSymbols(dfs);
        return (df.format(Double.parseDouble(moneyString))).toString();
    }
    /**
     * ±Ý¾×¹®ÀÚ¿­À» ±Ý¾×Ç¥½ÃŸÀÔÀ¸·Î º¯È¯ÇÑ´Ù. <BR>
     * (¿¹) 12345678 --> 12,345,678            <BR>
     * @param    moneyString ±Ý¾× .
     * @return   ±Ý¾×
     */
    public String makeMoneyType(int intMoneyString)
    {
        String moneyString = new Integer(intMoneyString).toString();
        DecimalFormat df = new DecimalFormat();
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setGroupingSeparator(',');
        df.setGroupingSize(3);
        df.setDecimalFormatSymbols(dfs);
        return (df.format(Double.parseDouble(moneyString))).toString();
    }
    /**
     * ±Ý¾×Ç¥½ÃŸÀÔÀ» ±Ý¾×¹®ÀÚ¿­·Î º¯È¯ÇÑ´Ù. <BR>
     * (¿¹) 12,345,678 --> 12345678          <BR>
     * @param    moneyString ±Ý¾×Ç¥½Ã¹®ÀÚ¿­.
     * @return   ±Ý¾×¹®ÀÚ¿­.
     */
    public String makeNoMoneyType(String moneyString)
    {
        StringTokenizer st = new StringTokenizer(moneyString, ",");
        String out = "";
        String temp = null;
        while (st.hasMoreTokens())
        {
            temp = st.nextToken();
            out = out + temp;
        }
        return out;
    }
    /**
     * StringÀ» int°ªÀ¸·Î º¯È¯ÇÑ´Ù.           <BR>
     *
     * @param    str     int°ªÀ¸·Î º¯È¯µÉ String¹®ÀÚ¿­.
     * @return   º¯È¯µÈ int °ª.
     */
    public int stoi(String str)
    {
        if (str == null)
        {
            return 0;
        }
        return (Integer.valueOf(str).intValue());
    }
    /**
     * int°ªÀ» StringÀ¸·Î º¯È¯ÇÑ´Ù.           <BR>
     *
     * @param    i   StringÀ¸·Î º¯È¯µÉ int °ª.
     * @return   º¯È¯µÈ String °ª.
     */
    public String itos(int i)
    {
        return (new Integer(i).toString());
    }
    /**
     * ¹®ÀÚ¿­À» ġȯ
     * @param src ´ë»ó±Û
     * @param from º¯°æÇÒ ¹®ÀÚ
     * @param to º¯°æµÉ ¹®ÀÚ
     * @return º¯°æµÈ ÀÌÈÄ ¹®ÀÚ
     */
    public String replace(String src, String from, String to) throws Exception
    {
        if (src == null)
        {
            return null;
        }
        if (from == null)
        {
            return src;
        }
        if (to == null)
        {
            to = "";
        }
        StringBuffer buf = new StringBuffer();
        for (int pos; (pos = src.indexOf(from)) >= 0; )
        {
            buf.append(src.substring(0, pos));
            buf.append(to);
            src = src.substring(pos + from.length());
        }
        buf.append(src);
        return buf.toString();
    }
    /**
     * ÀÏÁ¤ÇÑ ±æÀÌ·Î ¹®ÀÚ¸¦ ÀÚ¸§
     * @param str ÀÚ¸¦ ¹®ÀÚ
     * @param limit ÀÚ¸¦ ¼ö
     * @return º¯°æµÈ ÀÌÈÄ ¹®ÀÚ
     */
    public String cutString(String str, int limit)
    {
        if (str == null)
        {
            return str;
        }
        int len = str.length();
        int cnt = 0, index = 0;
        while (index < len && cnt < limit)
        {
            if (str.charAt(index++) < 256) // 1¹ÙÀÌÆ® ¹®ÀÚ¶ó¸é...
            {
                cnt++; // ±æÀÌ 1 Áõ°¡
            }
            else // 2¹ÙÀÌÆ® ¹®ÀÚ¶ó¸é...
            {
                cnt += 2; // ±æÀÌ 2 Áõ°¡
            }
        }
        if (index < len)
        {
            str = str.substring(0, index) + "...";
        }
        return str;
    }
    /**
     * µÎ°³ÀÇ ¹®ÀÚ¿­À» ºñ±³ÇÏ¿© °°Àº ¹®ÀÚ¿­À̸é true, ´Ù¸¥ ¹®ÀÚ¿­À̸é false¸¦ ¸®ÅÏÇÑ´Ù.
     * @param sOne ºñ±³ÇÒ ¹®ÀÚ¿­1
     * @param sOne ºñ±³ÇÒ ¹®ÀÚ¿­2
     * @return °°Àº ¹®ÀÚ¿­À̸é true, ´Ù¸¥ ¹®ÀÚ¿­À̸é false
     */
    public boolean stringCompare(String sOne, String sTwo)
    {
        if (sOne == null && sTwo == null)
        {
            return true;
        }
        if (sOne == null && sTwo != null)
        {
            return false;
        }
        if (sOne != null && sTwo == null)
        {
            return false;
        }
        return sOne.equals(sTwo);
    }
    /**
     * ½Ç¼ö¸¦ ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö¸¸ ÃëÇÏ°í ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param f ´ë»ó floatÇü ÀÚ·á
     * @param num ¼Ò¼öÁ¡ÀÌÇÏ ÀÚ¸®¼ö
     * @return ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁöÀ߸° ½Ç¼ö <br><br>
       <b>±âŸ :</b> ¹Ý¿Ã¸² ¾Æ´Ô ¿¹) roundCutFloat(33.236f , 2) => 33.23
     */
    public float roundCutFloat(float f, int num)
    {
        String sTargetFloat = Float.toString(f);
        StringTokenizer stk = new StringTokenizer(sTargetFloat, ".");
        String sIntPart = stk.nextToken();
        String sFloPart = stk.nextToken();
        if (num > sFloPart.length())
        {
            return f;
        }
        else
        {
            sFloPart = sFloPart.substring(0, num);
            String sReturnFloat = sIntPart + "." + sFloPart;
            return Float.parseFloat(sReturnFloat);
        }
    }
    /**
     * doubleÇü ½Ç¼ö¸¦ ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö¸¸ ÃëÇÏ°í ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param d ´ë»ó doubleÇü ÀÚ·á
     * @param num ¼Ò¼öÁ¡ÀÌÇÏ ÀÚ¸®¼ö
     * @return ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁöÀ߸° doubleÇü ½Ç¼ö <br><br>
       <b>±âŸ :</b> ¹Ý¿Ã¸² ¾Æ´Ô ¿¹) roundCutFloat(33.236 , 2) => 33.23
     */
    public double roundCutDouble(double d, int num)
    {
        double decimalPosition = Math.pow(10D, num);
        double ReturnValue = Math.floor(d * decimalPosition) / decimalPosition;
        return ReturnValue;
    }
    /**
     * ½Ç¼ö¸¦ ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö¸¸ ¹Ý¿Ã¸²ÇÏ¿© ¸®ÅÏÇÑ´Ù.
     * @param f ´ë»ó floatÇü ÀÚ·á
     * @param position ¼Ò¼öÁ¡ÀÌÇÏ ÀÚ¸®¼ö
     * @return ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö ¹Ý¿Ã¸²ÇÑ ½Ç¼ö <br><br>
       <b>±âŸ :</b> ¿¹) roundHalfFloat(33.236 , 2) => 33.24
     */
    public float roundHalfFloat(float f, int position)
    {
        double decimalPosition = Math.pow(10D, position);
        float ReturnValue = (float) ( (double) Math.round( (double) f *
            decimalPosition) / decimalPosition);
        return ReturnValue;
    }
    /**
     * doubleÇü ½Ç¼ö¸¦ ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö¸¸ ¹Ý¿Ã¸²ÇÏ¿© ¸®ÅÏÇÑ´Ù.
     * @param d ´ë»ó doubleÇü ÀÚ·á
     * @param position ¼Ò¼öÁ¡ÀÌÇÏ ÀÚ¸®¼ö
     * @return ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö ¹Ý¿Ã¸²ÇÑ doubleÇü ½Ç¼ö <br><br>
       <b>±âŸ :</b> ¿¹) roundHalfDouble(33.236 , 2) => 33.24
     */
    public double roundHalfDouble(double d, int position)
    {
        double decimalPosition = Math.pow(10D, position);
        double ReturnValue = (double) Math.round(d * decimalPosition) /
            decimalPosition;
        return ReturnValue;
    }
    /**
     * ½Ç¼ö¸¦ ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö¸¸ ¿Ã¸²ÇÏ¿© ¸®ÅÏÇÑ´Ù.
     * @param f ´ë»ó floatÇü ÀÚ·á
     * @param position ¼Ò¼öÁ¡ÀÌÇÏ ÀÚ¸®¼ö
     * @return ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö ¿Ã¸²ÇÑ ½Ç¼ö <br><br>
       <b>±âŸ :</b> ¿¹) roundAllFloat(33.231 , 2) => 33.24
     */
    public float roundAllFloat(float f, int position)
    {
        double decimalPosition = Math.pow(10D, position);
        float ReturnValue = (float) (Math.ceil( (double) f * decimalPosition) /
                                     decimalPosition);
        return ReturnValue;
    }
    /**
     * doubleÇü ½Ç¼ö¸¦ ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö¸¸ ¿Ã¸²ÇÏ¿© ¸®ÅÏÇÑ´Ù.
     * @param d ´ë»ó doubleÇü ÀÚ·á
     * @param position ¼Ò¼öÁ¡ÀÌÇÏ ÀÚ¸®¼ö
     * @return ÁöÁ¤µÈ ¼Ò¼öÁ¡ ÀÚ¸®±îÁö ¿Ã¸²ÇÑ doubleÇü ½Ç¼ö <br><br>
       <b>±âŸ :</b> ¿¹) roundAllDouble(33.231 , 2) => 33.24
     */
    public double roundAllDouble(double d, int position)
    {
        double decimalPosition = Math.pow(10D, position);
        double dRtn = Math.ceil(d * decimalPosition) / decimalPosition;
        return dRtn;
    }
    /**
     * ¼ýÀÚ¸¦ ÇØ´ç ÀÚ¸´¼ö ¸¸Å­ ¾Õ¿¡ 0À» ºÙ¿© ½ºÆ®¸µÀ¸·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param original ´ë»ó Á¤¼ö
     * @param digit Àüü ÀÚ¸®¼ö
     * @return º¯ÇüµÈ ¹®ÀÚ¿­ <br><br>
       <b>±âŸ :</b> ¿¹) toLeadingZeroString(223,5) => "00223"
     */
    public String toLeadingZeroString(int original, int digit)
    {
        String result = "";
        String tr = Integer.toString(original);
        for (int i = 1; i <= digit - tr.length(); i++)
        {
            result = result + "0";
        }
        return result + tr;
    }
    /**
     * NULLÀ» ºó¹®ÀÚ¿­("")·Î ¸®ÅÏÇÑ´Ù.
     * @param str nullÀ» üũÇÒ ¹®ÀÚ¿­
     * @return ³Î¿©ºÎ¸¦ üũÇÑ ¹®ÀÚ¿­ <br><br>
     */
    public String nullToEmptyString(String str)
    {
        if (str == null)
        {
            return "";
        }
        if ("null".equals(str))
        {
            return "";
        }
        else
        {
            return str.trim();
        }
    }
    /**
     * ¹®ÀÚ¸¦ substring ÇÒ¶§ ÇØ´ç target ¹®ÀÚ°¡ nullÀÏ°æ¿ì substring ÇÏÁö¾Ê°í ""À¸·Î ¸®ÅÏÇÏ´Â ¸Þ½îµå
     * @param str ¿øº» ¹®ÀÚ¿­
     * @param beginIndex substringÇÒ Ã¹¹ø° À妽º
     * @return ³Î¿©ºÎ¸¦ üũÇÑ ¹®ÀÚ¿­ <br><br>
       <b>±âŸ :</b> ¿¹) toSubString("abcd" , 2) => "cd"
     */
    public String toSubString(String str, int beginIndex)
    {
        String ret = null;
        String str_temp = null;
        str_temp = nullToEmptyString(str);
        if ("".equals(str_temp))
        {
            return str_temp;
        }
        else
        {
            ret = str.substring(beginIndex);
            return ret;
        }
    }
    /**
     * ¹®ÀÚ¸¦ substring ÇÒ¶§ ÇØ´ç target ¹®ÀÚ°¡ nullÀÏ°æ¿ì substring ÇÏÁö¾Ê°í ""À¸·Î ¸®ÅÏÇÏ´Â ¸Þ½îµå
     * @param str ¿øº» ¹®ÀÚ¿­
     * @param beginIndex substringÇÒ Ã¹¹ø° À妽º
     * @param endIndex substringÇÒ ¸¶Áö¸· À妽º
     * @return ³Î¿©ºÎ¸¦ üũÇÑ ¹®ÀÚ¿­ <br><br>
       <b>±âŸ :</b> ¿¹) toSubString("abcd" , 2,3) => "d"
     */
    public String toSubString(String str, int beginIndex, int endIndex)
    {
        String ret = null;
        String str_temp = null;
        str_temp = nullToEmptyString(str);
        if ("".equals(str_temp))
        {
            return str_temp;
        }
        else
        {
            ret = str.substring(beginIndex, endIndex);
            return ret;
        }
    }
    /**
     * String À» English¿¡¼­ Korean charsetÀ¸·Î µðÄÚµù
     * @param str ¿øº» ¹®ÀÚ¿­
     * @return Korean charsetÀ¸·Î µðÄÚµùµÈ ¹®ÀÚ¿­ <br><br>
     */
    public String EnglishToKorean(String str)
    {
        try
        {
            if (str == null)
            {
                return null;
            }
            else
            {
                return new String(str.getBytes("8859_1"), "KSC5601");
            }
        }
        catch (Exception e)
        {
            System.out.println("Error on EnglishToKorean");
        }
        return null;
    }
    /**
     * String À» Korean¿¡¼­ English charsetÀ¸·Î µðÄÚµù
     * @param str ¿øº» ¹®ÀÚ¿­
     * @return English charsetÀ¸·Î µðÄÚµùµÈ ¹®ÀÚ¿­ <br><br>
     */
    public String KoreanToEnglish(String str)
    {
        try
        {
            if (str == null)
            {
                return null;
            }
            else
            {
                return new String(str.getBytes("KSC5601"), "8859_1");
            }
        }
        catch (Exception e)
        {
            System.out.println("Error on KoreanToEnglish");
        }
        return null;
    }
    /**
     * double ÇüÅÂÁß 9.0E9 ¸¦ 900000000 ½ÄÀ¸·Î ³ªÅ¸³»´Â ÇÔ¼ö
     * @param dParam ¿øº» doubleÇü
     * @return String stringÇü¹®ÀÚ <br><br>
     */
    public String doubleChangeString(double dParam)
    {
        String sRtn = null;
        NumberFormat nf = NumberFormat.getInstance();
        return nf.format(dParam);
    }
    /**
     * textAreaÀÇ Data¸¦ HTML ³»ÀÇ Table¿¡ º¸¿©ÁÖ°íÀÚ ÇÒ ¶§ Ư¼ö¹®ÀÚ Ã³¸®ÇÏ´Â ¸Þ¼Òµå
     * \n¸¦ "\, " \"¸¦ "\"", <¸¦ "\<", >¸¦ "\>", °ø¹é¸¦ "\ ", &¸¦ "\&" ·Î º¯È¯
     * ÀԷ¹ÞÀº ½ºÆ®¸µÀÌ nullÀÎ °æ¿ì Empty String("") ¸®ÅÏ
     * @param str ¿øº» ¹®ÀÚ¿­
     * @return String º¯È¯µÈ ¹®ÀÚ¿­<br><br>
     */
    public String textAreaToPage(String str)
    {
        int maxwidth = 100;
        String ret = "";
        int endindex = 0;
        str = nullToEmptyString(str);
        if ("" != str)
        {
            endindex = str.indexOf('\n');
            if (endindex != str.length())
            {
                for (endindex = 0; endindex >= 0; )
                {
                    endindex = str.indexOf('\n');
                    if (endindex != -1)
                    {
                        if (endindex > maxwidth)
                        {
                            ret = ret + str.substring(0, maxwidth) + "<br>";
                            str = str.substring(maxwidth, str.length());
                            endindex -= maxwidth;
                        }
                        else
                        {
                            ret = ret + str.substring(0, endindex - 1) + "<br>";
                            str = str.substring(endindex + 1, str.length());
                        }
                    }
                }
                str = ret + str;
            }
        }
        return str;
    }
    /**
     * ÇÑ String¿¡ ¿øÇÏ´Â ¹®ÀÚ°¡ ¸î °³ Æ÷ÇԵǾî ÀÖ´ÂÁö ÆľÇÇÏ´Â method
     * @param str ºñ±³ÇÏ·Á´Â ¹®Àå
     * @param str ãÀ¸·Á´Â ¹®ÀÚ
     * @return String º¯È¯µÈ ¹®ÀÚ¿­<br><br>
     */
    public int charCounter(String str, String delim)
    {
        int indx = 0;
        int icount = 0;
       
        if(nullToEmptyString(delim).equals(""))
     {
      return 0;
     }
     else
     {
         for (indx = str.indexOf(delim); indx != -1; )
         {
             str = str.substring(str.indexOf(delim) + 1, str.length());
             indx = str.indexOf(delim);
             icount++;
         }
  }
 
        return icount;
    }

    /**
     * ÇÑ String¿¡ ¿øÇϴ Ư¼ö¹®ÀÚ°¡ ¸î °³ Æ÷ÇԵǾî ÀÖ´ÂÁö ÆľÇÇÏ´Â method
     * @param str ºñ±³ÇÏ·Á´Â ¹®Àå
     * @param str ãÀ¸·Á´Â ¹®ÀÚ
     * @return String º¯È¯µÈ ¹®ÀÚ¿­<br><br>
     */
    public int specialCharCounter(String str, String delim)
    {
        int indx = 0;
        int icount = 0;
        StringTokenizer st = null;
       
        if(nullToEmptyString(str).equals(""))
     {
      return 0;
     }
     else
     {
      st = new StringTokenizer(str, delim);
         while (st.hasMoreTokens())
         {
          st.nextToken();
             icount++;
         }
  }
 
        return icount;
    }
    /**
     * ¹®ÀÚ°¡ null,"","null" ÀÎ °æ¿ì ÇØ´ç ¹®ÀÚ¸¦ 0À¸·Î ä¿öÁÖ´Â ¸Þ¼Òµå
     * @param str ºñ±³ÇÏ·Á´Â ¹®Àå
     * @return String ¹®ÀÚ¿­<br><br>
     */
    public String nullToZero(String str)
    {
        String returnCheck = null;
        if (stringCompare("", str) || stringCompare("null", str) || str == null)
        {
            returnCheck = "0";
        }
        else
        {
            returnCheck = str;
        }
        return returnCheck;
    }
    /**
     * ¹®ÀÚ¿­¿¡¼­ ÇØ´ç ¹®ÀÚ·Î ¹®ÀÚ¿­À» Àß¶ó¼­ ¹è¿­·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param s ´ë»ó¹®ÀÚ¿­
     * @param token ÀÚ¸£·Á´Â ¹®ÀÚ
     * @return string[] ¹®ÀÚ¿­¹è¿­<br><br>
     */
    public String[] cutTokenToArray(String s, String token) throws
        RemoteException
    {
        StringTokenizer stz = new StringTokenizer(s, token);
        String result[] = new String[stz.countTokens()];
        try
        {
            for (int j = 0; j < result.length; j++)
            {
                result[j] = stz.nextToken();
            }
        }
        catch (Exception exception)
        {
            System.out.println(exception.getMessage());
        }
        return result;
    }

    public String getProgramName(Object oProgramName, String sGubun)
    {
        String sName = null;
        String sReturn = null;
        int iLast = 0;
        try
        {
            if ("J" == sGubun)
            {
                sName = oProgramName.getClass().getName();
                iLast = sName.lastIndexOf(".");
                sReturn = sName.substring(iLast + 2) + ".jsp";
            }
            else if ("B" == sGubun)
            {
                StringTokenizer stBean = new StringTokenizer(oProgramName.
                    getClass().getName());
                String sOneBean = stBean.nextToken(".");
                String sTwoBean = stBean.nextToken(".");
                String sThreeBean = stBean.nextToken(".");
                String sFourBean = stBean.nextToken(".");
                String sFiveBean = stBean.nextToken(".");
                String sSixBean = stBean.nextToken(".");
                sReturn = sSixBean + ".java";
            }
            else
            {
                sReturn = "";
            }
        }
        catch (Exception ex)
        {
            System.out.println("Error  getProgramName ");
        }
        return sReturn;
    }
    /**
     * ÆĶó¹ÌÅÍ·Î ¹ÞÀº °ªÀ» null ¶Ç´Â ÇØ´ç StringÀ¸·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param request request°´Ã¼
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return string null°´Ã¼,null¹®ÀÚ,Empty StringÀº null°´Ã¼·Î ¸®ÅÏ <br>
               Á¤»óÀûÀÎ StringÀº trim()ÇÏ°í ¸®ÅÏ <br><br>
     */
    public String getCheckParameter(HttpServletRequest request,
                                    String sParameterName)
    {
        String sCheckParameter = request.getParameter(sParameterName);
        if (jspKoreanToEnglish)
        {
           sCheckParameter = EnglishToKorean(sCheckParameter);
        }
        if (sCheckParameter == null || "null".equals(sCheckParameter) ||
            sCheckParameter.trim().length() == 0)
        {
            return null;
        }
        else
        {
            return sCheckParameter.trim();
        }
    }
    /**
     * ÆĶó¹ÌÅÍ·Î ¹ÞÀº °ªÀ» null ¶Ç´Â ÇØ´ç StringÀ¸·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param request request°´Ã¼
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return string¹è¿­<br><br>
     */
    public String[] getCheckParameterValues(HttpServletRequest request,
                                            String sParameterName)
    {
        String sCheckParameterArray[] = request.getParameterValues(
            sParameterName);
        if (getLength(sCheckParameterArray) == 0)
        {
            return null;
        }
        String sReturn[] = new String[getLength(sCheckParameterArray)];
        for (int i = 0; i < getLength(sCheckParameterArray); i++)
        {
            if (bKoreanToEnglish)
            {
                sReturn[i] = EnglishToKorean(sCheckParameterArray[i]);
            }
            else
            {
                sReturn[i] = sCheckParameterArray[i];
            }
        }
        return sReturn;
    }
   
    /**
     * ÆĶó¹ÌÅÍ·Î ¹ÞÀº °ªÀ» null ¶Ç´Â ÇØ´ç StringÀ¸·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param multi MultipartRequest
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return string null°´Ã¼,null¹®ÀÚ,Empty StringÀº null°´Ã¼·Î ¸®ÅÏ <br>
               Á¤»óÀûÀÎ StringÀº trim()ÇÏ°í ¸®ÅÏ <br><br>
     */
    public String getCheckParameterMulti(MultipartRequest multi,
                                    String sParameterName)
    {
        String sCheckParameter = multi.getParameter(sParameterName);
        if (jspKoreanToEnglish)
        {
           sCheckParameter = EnglishToKorean(sCheckParameter);
        }
        if (sCheckParameter == null || "null".equals(sCheckParameter) ||
            sCheckParameter.trim().length() == 0)
        {
            return null;
        }
        else
        {
            return sCheckParameter.trim();
        }
    }
    /**
     * ÆĶó¹ÌÅÍ·Î ¹ÞÀº °ªÀ» null ¶Ç´Â ÇØ´ç StringÀ¸·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param request request°´Ã¼
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return string¹è¿­<br><br>
     */
    public String[] getCheckParameterValuesMulti(MultipartRequest multi,
                                            String sParameterName)
    {
        String sCheckParameterArray[] = multi.getParameterValues(
            sParameterName);
        if (getLength(sCheckParameterArray) == 0)
        {
            return null;
        }
        String sReturn[] = new String[getLength(sCheckParameterArray)];
        for (int i = 0; i < getLength(sCheckParameterArray); i++)
        {
            if (bKoreanToEnglish)
            {
                sReturn[i] = EnglishToKorean(sCheckParameterArray[i]);
            }
            else
            {
                sReturn[i] = sCheckParameterArray[i];
            }
        }
        return sReturn;
    }
    /**
     * ÆĶó¹ÌÅÍ·Î ¹ÞÀº °ªÀ» 0 ¶Ç´Â ÇØ´ç integer·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param request request°´Ã¼
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return int°ª<br><br>
     */
    public int getCheckIntParameter(HttpServletRequest request,
                                    String sParameterName)
    {
        String sCheckParameter = request.getParameter(sParameterName);
        if (sCheckParameter == null || "null".equals(sCheckParameter) ||
            sCheckParameter.trim().length() == 0)
        {
            return 0;
        }
        else
        {
            return Integer.parseInt(sCheckParameter.trim());
        }
    }
    /**
     * ÆĶó¹ÌÅÍ·Î ¹ÞÀº °ªÀ» 0.0 ¶Ç´Â ÇØ´ç double·Î ¸®ÅÏÇÏ´Â ¸Þ¼Òµå
     * @param request request°´Ã¼
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return double°ª<br><br>
     */
    public double getCheckDoubleParameter(HttpServletRequest request,
                                          String sParameterName)
    {
        String sCheckParameter = request.getParameter(sParameterName);
        if (sCheckParameter == null || "null".equals(sCheckParameter) ||
            sCheckParameter.trim().length() == 0)
        {
            return 0.0;
        }
        else
        {
            return Double.parseDouble(sCheckParameter.trim());
        }
    }
    /**
     * String, long[], double[], String[], String[][](ù¹ø° ±âÁØ¿­), Object[]ÀÇ length¸¦ ±¸ÇÔ
     * @param request request°´Ã¼
     * @param sParameterName ¹Þ°íÀÚÇÏ´Â Parameter À̸§
     * @return int¹è¿­°ª<br><br>
     */
    public int getLength(Object oValue)
    {
        int iValue = 0;
        if (oValue instanceof String)
        {
            String one = (String) oValue;
            if ( (String) oValue == null)
            {
                return iValue;
            }
            else
            {
                return one.length();
            }
        }
        if (oValue instanceof String[])
        {
            String two[] = (String[]) oValue;
            if ( (String[]) oValue == null)
            {
                return iValue;
            }
            else
            {
                return two.length;
            }
        }
        if (oValue instanceof String[][])
        {
            String three[][] = (String[][]) oValue;
            if ( (String[][]) oValue == null)
            {
                return iValue;
            }
            else
            {
                return three.length;
            }
        }
        else
        {
            return iValue;
        }
    }
    public String getCDInSelectBoxWithCon(Connection conn, String sSelectName, String sDefaultSelect,
                                   String sDefaultCap, String sChangeEvent,
                                   String sSql) throws Exception
    {
        StringBuffer sSelectBox = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sDefaultSelected = "";
        String sSelected = "";
        try
        {
            // Sql¹® ÀÛ¼º
            //ÆĶó¸ÞÅÍ ¼¼ÆÃÇÑ´Ù.
            ps = conn.prepareStatement(sSql);
            rs = ps.executeQuery();
            sSelectBox = new StringBuffer();
            if (!sChangeEvent.equals(""))
            {
                sSelectBox.append("<select name='" + sSelectName +
                                  "' omChange=" + sChangeEvent + " omKeyDown=cfMoveTabIndex()>");
            }
            else
            {
                sSelectBox.append("<select name='" + sSelectName + "' omKeyDown=cfMoveTabIndex()>");
            }
            if (sDefaultSelect.equals(""))
            {
                sDefaultSelected = "selected";
            }
            else
            {
                sSelected = "selected";
            }
            if (!sDefaultCap.equals(""))
            {
                sSelectBox.append("<option value='' " + sDefaultSelected + ">" +
                                  sDefaultCap + "</option>");
            }
            while (rs.next())
            {
                if (!sDefaultSelected.equals("selected") &&
                    rs.getString("CD").equals(sDefaultSelect))
                {
                    sSelectBox.append("<option value='" + rs.getString("CD") +
                                      "' selected >" + rs.getString("CD_NM") +
                                      "</option>");
                }
                else
                {
                    sSelectBox.append("<option value='" + rs.getString("CD") +
                                      "'>" + rs.getString("CD_NM") +
                                      "</option>");
                }
            }
            sSelectBox.append("</select>");
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        finally
        {
            try
            {
                if (rs != null)
                {
                    rs.close();
                }
                if (ps != null)
                {
                    ps.close();
                }
            }
            catch (Exception ex)
            {
                System.out.println(ex.getMessage());
            }
        }
        return sSelectBox.toString();
    }
    public String getCDInSelectBox(String sSelectName, String sDefaultSelect,
                                   String sDefaultCap, String sChangeEvent,
                                   String sSql) throws Exception
    {
        StringBuffer sSelectBox = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
        String sDefaultSelected = "";
        String sSelected = "";
        try
        {
            conn = CmJDBCConnection.getConnection();
            System.out.println("Connection ¿¬°á");
            // Sql¹® ÀÛ¼º
            //ÆĶó¸ÞÅÍ ¼¼ÆÃÇÑ´Ù.
            ps = conn.prepareStatement(sSql);
            rs = ps.executeQuery();
            sSelectBox = new StringBuffer();
            if (!sChangeEvent.equals(""))
            {
                sSelectBox.append("<select name='" + sSelectName +
                                  "' omChange=" + sChangeEvent + " omKeyDown=cfMoveTabIndex()>");
            }
            else
            {
                sSelectBox.append("<select name='" + sSelectName + "' omKeyDown=cfMoveTabIndex()>");
            }
            if (sDefaultSelect.equals(""))
            {
                sDefaultSelected = "selected";
            }
            else
            {
                sSelected = "selected";
            }
            if (!sDefaultCap.equals(""))
            {
                sSelectBox.append("<option value='' " + sDefaultSelected + ">" +
                                  sDefaultCap + "</option>");
            }
            while (rs.next())
            {
                if (!sDefaultSelected.equals("selected") &&
                    rs.getString("CD").equals(sDefaultSelect))
                {
                    sSelectBox.append("<option value='" + rs.getString("CD") +
                                      "' selected >" + rs.getString("CD_NM") +
                                      "</option>");
                }
                else
                {
                    sSelectBox.append("<option value='" + rs.getString("CD") +
                                      "'>" + rs.getString("CD_NM") +
                                      "</option>");
                }
            }
            sSelectBox.append("</select>");
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        finally
        {
            try
            {
                if (rs != null)
                {
                    rs.close();
                }
                if (ps != null)
                {
                    ps.close();
                }
                if (conn != null)
                {
                    conn.close();
                }
            }
            catch (Exception ex)
            {
                System.out.println(ex.getMessage());
            }
        }
        return sSelectBox.toString();
    }
//////////////////// Made by Shin woochoul
    public HashMap requestDataProcessing(HttpServletRequest req)
    {
        HashMap insertMap = new HashMap();
        HashMap updateMap = new HashMap();
        HashMap deleteMap = new HashMap();
        HashMap selectMap = new HashMap();
        System.out.println("######################################");
        String command = req.getParameter("hiddenWorkGubn"); // insert,update,delete,select
        System.out.println("Utility- :command :" + command);
        System.out.println("######################################");
        if (command.equals("insert"))
        {
            insertMap = getData(req);
        }
        else if (command.equals("update"))
        {
            updateMap = getData(req);
//System.out.println("UU------------" + updateMap.toString() );
        }
        else if (command.equals("delete"))
        {
            deleteMap = getData(req);
        }
        else
        {
            selectMap = getData(req);
        }
        HashMap crudMap = new HashMap(4);
        crudMap.put("insert", insertMap);
        crudMap.put("update", updateMap);
        crudMap.put("delete", deleteMap);
        crudMap.put("select", selectMap);
        return crudMap;
    }
    /**
     * @param req Client¿¡¼­ ¹ÞÀº RequestÁ¤º¸
     * @param row Client¿¡¼­ ¹ÞÀº ¸®½ºÆ®ÀÇ row °³¼ö
     * @return map Request ·Î ¹ÞÀº Á¤º¸
     */
    public HashMap getData(HttpServletRequest req)
    {
        System.out.println("22######################################getData1");
        HashMap map = new HashMap(req.getParameterMap());
        System.out.println("22######################################getData2" +
                           map);
        return map;
    }
 
    public String specialLetterChange(String str)
    {
        String sRtn = "";
       sRtn = str.replaceAll("\n", "\\\\n");
       sRtn = sRtn.replaceAll("\r", "\\\\r");
       sRtn = sRtn.replaceAll( "'", "\\\\'");
       sRtn = sRtn.replaceAll( "\"", "\\\\\"");
     return sRtn;
    }
    /**
     * @param length º¸¿©ÁÙ ¹®ÀÚ¿­ÀÇ ±æÀÌ
     * @param str    ¿ø¹®ÀÚ¿­
     * @return TargetStr º¸¿©ÁÙ¹®ÀÚ¿­±æÀÌ+... ´õÇØÁø ¹®ÀÚ¿­
     */
 public String StringToDot(int length, String str)
 {
  String TempStr = null;
  if(str.length() < length)
  {
   TempStr = str;
  }
  else
  {
   TempStr = (String)(str).substring(0, length) + "...";
  }
  return TempStr;
 }
///////////////////////////////////////////
}

ÀλýÀº ª½À´Ï´Ù.
±×·¯¹Ç·Î ´Ù¸¥ »ç¶÷ÀÌ ¿ä±¸ÇÏ´Â »îÀ» »ì¸é¼­ ½Ã°£À» ³¶ºñÇؼ­´Â ¾È µË´Ï´Ù.
µ·°ú ¸í¿¹¸¦ ¾òÁö ¸øÇÏ´õ¶óµµ ³¡±îÁö ÀÚ½ÅÀÇ ±æÀ» °íÁýÇϽʽÿÀ
¸ñ·Ï À­±Û ¾Æ·§±Û
³»¾Ë FREECOUNT.NET ÇÁÄ«³Ý »ý±ä³¯ 2003.12.20 Ȩ | Ä«¿îÅÍ | Ç÷¡½ÃºÏ | ÇÁ¸®º¸µå | Àü±¤ÆÇ | À¥°øºÎ¹æ | Ä¿¹Â´ÏƼ | ÂÊÁöÇÔ