[Âü°í] encodeµÈ urlÀ» decodeÇϱâ


[ Follow Ups ] [ Post Followup ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

Posted by ¹ÚÁø¿ì on June 18, 1997 at 12:50:21:

In Reply to: [Áú¹®] urlencoded String¿¡¼­ ÇÑ±Û ¹®ÀÚ¿­ ¾ò±â posted by °­½Åµ¿ on June 13, 1997 at 16:00:51:

¾È³çÇϼ¼¿ä.
¹ÚÁø¿ì ÀÔ´Ï´Ù.


servletÀº ¸¹ÀÌ °øºÎ ÇÏÁú ¾Ê¾Æ¼­
¾ÆÁ÷ servlet package´Â º¸Áú ¸øÇؼ­
´äÀÌ µÉÁö ¸ð¸£°ÚÁö¸¸ ´ë°­ encode¿¡ ´ëÇØ Àû¾î º¸°ÚÀ¾´Ï´Ù.


java ±âº» package¿¡´Â url encodeÇÏ´Â URLEncoder¿¡ encode()´Â
ÀÖÁö¸¸ urlÀ» decodeÇÏ´Â method°¡ ¾ø¾î¼­ URLDecoder class´Â
Á÷Á¢ ¸¸µé¾î »ç¿ëÇØ¾ß Çϰŵç¿ä.


´ë°­ ¾Æ·¡¿Í °°ÀÌ URLDecoder¸¦ ¸¸µé¾î ºÃ´Âµ¥ ¿¹Á¦ Çü½ÄÀ¸·Î
¸¸µé¾úÀ¾´Ï´Ù.


encodeµÈ StringÀ» ASCIIÇüÅ·Π´Ù½Ã decode½ÃÄÑ StringÀ¸·Î
return ½ÃÅ°´Â ¿¹Á¦ÀÔ´Ï´Ù.


Çѱ۵µ Àß µÇ³×¿ä...



import java.io.*;
import java.net.*;


class HanTest
{ public static void main(String[] args)
{ String u1 = URLEncoder.encode("¿À ±×´ë´Â ¾Æ¸§´Ù¿î ¿©ÀÎ");
System.out.println(u1);
String u2 = URLDecoder.decode(u1);
System.out.println(u2);
}
}


class URLDecoder
{ private URLDecoder()
{}
public static String decode(String s)
{ ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
for (int i = 0; i < s.length(); i++)
{ int c = (int) s.charAt(i);
if ( c == '+') out.write(' ');
else if (c == '%')
{ int c1 = Character.digit(s.charAt(++i), 16);
int c2 = Character.digit(s.charAt(++i), 16);
out.write((char) (c1 * 16 + c2));
}
else out.write(c);
}
return out.toString();
}
}




ÀÚ¼¼ÇÑ ³»¿ëÀº
telnet bit.bbs.co.kr ÀÚ¹Ù µ¿È£È¸¿¡ ±ÛÀ» ¿Ã·Á ³ùÀ¸´Ï±î¿ä.
½Ã°£ÀÌ ÀÖÀ¸½Ã¸é ÀÌ°÷¿¡ ¿Í¼­ Çѹø º¸½Ã±¸¿ä.
---> Âü°í ÀÌ°÷Àº °¡ÀÔ°ú »ç¿ëÀÌ °øÂ¥ÀÓ.
---> ÀüÈ­Á¢¼ÓÀº ºÐ´ç 10¿ø. hitel-p¸¦ ÀÌ¿ëÇϹǷΠ±âº»ÀÌ¿ë·á
°¡ ºÙ´Â´Ù°í Çϳ׿ä.



Follow Ups:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ Follow Ups ] [ Post Followup ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]