Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


ÄíÅ°¿¡ ÇѱÛÀÌ µé¾î°¥ °æ¿ì ¿¹Á¦ ¼­ºí¸´
 
º¸Åë ÄíÅ°¿¡ ¿ì¸®°¡ ½Äº°ÇÒ ¼ö ÀÖ´Â Á¤º¸µîÀ» ÀÌ¿ëÇÏ¿© Ŭ¶óÀ̾ðÆ® »ç¿ëÀÚÀÇ ºê¶ó¿ìÁ®¸¦ ÀÌ¿ëÇÒ ¼ö Àִµ¥ Çѱۿ¡ ´ëÇÑ Ã³¸®¸¦ ¾î¶»°Ô ÇÒ°ÍÀÎÁö °£·«ÇÑ ¿¹Á¦¸¦ ÅëÇؼ­ ¾Ë¾Æº»´Ù. ( 2003/03/06 ) 148
Written by ienvyou - ÃÖÁö¿õ
1 of 1
 

°¢°¢ÀÇ Engine Vendor¿Í Á¦Ç°¿¡ µû¶ó Çѱ۱ÇÀÎ ¿ì¸®³ª¶ó¿¡¼­´Â ±ÛÀÚ°¡ ±úÁö´Â Çö»óÀ» ÀÚÁÖ
º¸°Ô µÈ´Ù. ÄíÅ° ¶ÇÇÑ ¸¶Âù°¡ÁöÀ̸ç, ²À ÄíÅ°¿¡¸¸ ±¹ÇÑµÈ ¹®Á¦°¡ ¾Æ´Ï¶ó°í º»´Ù.
¿©±â¼­´Â ÇØ´çµÇ´Â ÄíÅ°°ª¿¡ ÇѱÛÀ» ¼¼ÆýÃÅ°¸ç, ÄíÅ°¸¦ »ý¼ºÇÏ´Â ¹æ¹ýÀ» º¸µµ·Ï ÇÑ´Ù.
Çѱ۰ªÀ» ¼¼ÆýÃÅ°±â À§ÇØ µ¥ÀÌÅÍ°¡ Àü¼ÛµÇ¾îÁú¶§ÀÇ encoding¹æ¹ý°ú decoding¹æ¹ýÀ» ÀÌ¿ëÇÏ¿©
x-www-form-urlencoded ÇüÅ·Π½ºÆ®¸µÀ» ÀüȯÇÏ¿© ÇѱÛÀÌ ±úÁö´Â Çö»óÀ» ¹æÁöÇϵµ·Ï ÇÑ´Ù.


¾Æ·¡´Â ÄíÅ°¸¦ »ý¼ºÇÏ´Â ¼­ºí¸´ÃøÀÇ ¼Ò½ºÄÚµåÀÌ´Ù.




import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;

public class SetCookie extends HttpServlet {
	
public void doGet(HttpServletRequest req,HttpServletResponse res) 
	throws ServletException,IOException {
	res.setContentType("text/html; charset=euc-kr");
	PrintWriter out = res.getWriter();
	
	out.println("");
	out.println("Simple Korean Cookie Example");
	
	//Cookie Creation
	String str = "¾È³çÇϼ¼¿ä? javapatternÀÔ´Ï´Ù";
	Cookie ck = new Cookie("javapattern", URLEncoder.encode(str));
	
	//Expire Age Setting
	ck.setMaxAge(500);

	//Cookie setting
	res.addCookie(ck);
	out.println("" + str + "À» ÄíÅ°¿¡ ¼¼ÆýÃÄ×½À´Ï´Ù");
	out.println("Çѱ۰ªÀ» ÄíÅ°·Î ¼¼ÆýÃŵ´Ï´Ù.\n");
	out.println("GetCookie Servlet");
	out.close();
}
};

ÄíÅ°°ªÀº new Cookie()¿¡ ÀÇÇÏ¿© »ý¼ºµÇ¸ç, Çѹø¿¡ 4K¾¿ 20°³ÀÇ ÄíÅ°°ªÀ» Ŭ¶óÀ̾ðÆ®ÀÇ 
ºê¶ó¿ìÁ®¿¡ ÀúÀå ½Ãų ¼ö ÀÖ´Ù. 
´Ü Ŭ¶óÀ̾ðÆ®ÀÇ º¸¾È¿µ¿ª¿¡¼­ ÄíÅ° ¼³Á¤À» ÇÒ ¼ö ÀÖµµ·Ï µÇ¾î ÀÖ¾î¾ß ÇÑ´Ù´Â Á¶°ÇÀÌ ÀÖ´Ù
java.net package¿¡´Â ÇØ´ç µ¥ÀÌÅÍŸÀÔÀ» encodingÇÒ¼ö ÀÖ´Â URLEncoder¸¦ Á¦°øÇÏ°í ÀÖÀ¸¸ç, 
±×°ÍÀ» ¶ÇÇÑ ¿ªÀ¸·Î º¯È¯½Ãų¼ö ÀÖ´Â URLDecoder¸¦ Á¦°øÇÑ´Ù.
ÀÌÁ¦ Ŭ¶óÀ̾ðÆ®¿¡¼­ºÎÅÍ ÄíÅ°°ªÀ» °¡Á®¿À´Â Äڵ带 º¸µµ·Ï ÇÏÀÚ.


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;

public class GetCookie extends HttpServlet {
	
public void doGet(HttpServletRequest req,HttpServletResponse res) 
	throws ServletException,IOException {
	//Get Cookies
	Cookie all[]=req.getCookies();

	res.setContentType("text/html; charset=euc-kr");
	PrintWriter out = res.getWriter();
	
	out.println("");
	out.println("Simple Korean Cookie Example");
	
	out.println("Display Cookies Values");
	for(int i=0;i " + all[i].getName()+" : " + URLDecoder.decode(all[i].getValue())+"");
	}
	


	out.println("ÄíÅ° ÇѱÛÅ×½ºÆ® ³¡");
	out.close();
}
};



ÄíÅ°´Â Cookie all[]=req.getCookies();ÀÇ ÇüÅ·μ­ ÀúÀå½ÃÄѳõÀº ¸ðµç ÄíÅ°°ªÀ» °¡Á®¿Àµµ·Ï ÇÑ´Ù.
ÄíÅ°´Â »ý°¢°ú ´Þ¸® ±²ÀåÈ÷ ´Ü¼øÇÏ°Ô ¾µ¼ö ÀÖ°í °¡Á®¿Ã¼ö ÀÖ´Ù.
¿À´ÃÀº °£´ÜÇÏ°Ô »ìÆ캸¾ÒÀ¸³ª, ÀÌ·± °£´ÜÇÑ Äڵ嵵 °£°úÇÏ°í Áö³ª¼­´Â ¾ÈµÉ°ÍÀÌ´Ù.


Written by Carouser : 2001-05-14
 
1
References
 
http://java.sun.com/servlet
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD