Cookie Counter
import javax.servlet.*; error_handling
(e, "ERROR parsing temp to MAX_DIGIT");
return cookies[i]; public
void setCookie(HttpServletResponse res, String c_name)
{ public
void service (HttpServletRequest req,HttpServletResponse
res) throws ServletException, IOException { res.setContentType("text/html"); toClient.println("<table
border=0 cellpadding=0 cellspacing=0><tr>"); } À§ÀÇ ¼Ò½º´Â ¾Õ¿¡¼ ÀÛ¼ºÇß´ø Ä«¿îÅÍ ¼Ò½º¸¦ ¾à°£ ¼ÕÀ»
º» °ÍÀÔ´Ï´Ù. ¾Õ °Á¿¡¼ Cookie ¿¡ ´ëÇØ °øºÎÇÏ¿´À¸´Ï, ¹è¿î °ÍÀ»
½á ¸Ô¾î ºÁ¾ß ÇÏ°ÚÁö¿ä? ÀÌ Ä«¿îÅÍ´Â ¾ÕÀÇ Ä«¿îÅÍ¿Í ¹«¾ùÀÌ ´Ù¸¦±î¿ä? Å« Â÷ÀÌ´Â
¾ø½À´Ï´Ù. ´Ù¸¸ Çѹø µé¾î¿Ô´ø »ç¶÷ÀÌ ´Ù½Ã ÆäÀÌÁö¸¦ ¿ä±¸ ÇÏ´õ¶óµµ,
±× °ªÀÌ º¯ÇÏÁö ¾Ê´Â´Ù´Â Â÷ÀÌ »ÓÀÔ´Ï´Ù. ¹«½¼ ¼Ò¸®³Ä¸é, ¾î¶² »ç¶÷ÀÌ
Á¢¼ÓÇØ ¿À¸é, ±× »ç¶÷ÀÇ À¥ ºê¶ó¿ìÀú¿¡ Cookie¸¦ ¸¸µì´Ï´Ù. ±×¸®°í óÀ½
µé¾î¿ÔÀ¸¹Ç·Î, Ä«¿îÆ®¸¦ ¿Ã¸®°í, ȸ鿡 »Ñ·ÁÁÝ´Ï´Ù. ´Ù½Ã ±× »ç¶÷ÀÌ
µé¾î¿ÔÀ» ¶§´Â, ÄíÅ°ÀÇ À¯¹«¸¦ È®ÀÎÇÏ¿© ±×»ç¶÷ÀÌ ±âÁ¸¿¡ ¹æ¹®À» Çß´ø
»ç¶÷ÀÎÁö¸¦ È®ÀÎÇÕ´Ï´Ù. ±×·¡¼ ±âÁ¸¿¡ µé¾î¿Â ÀûÀÌ ÀÖÀ¸¸é, ÇöÀçÀÇ
Ä«¿îÆ® ¼ö¸¦ ±×³É »Ñ·ÁÁֱ⸸ ÇÏ´Â °ÍÀÔ´Ï´Ù. ±âÁ¸ÀÇ Ä«¿îÅÍ¿¡¼´Â »ç¿ëÀÚ°¡
µé¾î¿Í¼ Reload¸¦ ´©¸£¸é ´©¸¦ ¶§¸¶´Ù Ä«¿îÆ® ¼ö°¡ ´Ã¾î ³µÁö¸¸, À̹ø
Ä«¿îÅÍ´Â ´Ã¾î ³ªÁö ¾Ê´Â °ÍÀÌÁö¿ä. ´Ù¸¸ CookieÀÇ Á¾·á ½ÃÁ¡À» Default·Î
Ç߱⠶§¹®¿¡, À¥ ºê¶ó¿ìÀúÀÇ Á¾·á¿Í µ¿½Ã¿¡ ÄíÅ°´Â »ç¶óÁý´Ï´Ù. ±×·¡¼
´Ù½Ã À¥ ºê¶ó¿ìÀú¸¦ ±âµ¿½ÃŲÈÄ Á¢¼ÓÇϸé Ä«¿îÆ®°¡ Áõ°¡µË´Ï´Ù. ±×·³
ÀÌÁ¦ ¼Ò½º¸¦ ºÐ¼®ÇØ º¸°Ú½À´Ï´Ù. init ¸Þ¼Òµå¸¦ º¸¸é COOKIE_NAME = sc.getInitParameter("COOKIE_NAME"); ¶ó´Â °ÍÀÌ »õ·Î »ý°åÁö¿ä? »Ó¸¸ ¾Æ´Ï¶ó ¸â¹ö º¯¼ö¿¡µµ, String COOKIE_NAMEÀÌ
»õ·ÎÀÌ ¸¸µé¾ú½À´Ï´Ù. ÀÌ°Ç Cookie¸¦ »ý¼ºÇÒ ¶§ »ç¿ëÇÒ CookieÀÇ À̸§ÀÌ
µË´Ï´Ù. Cookie¿¡´Â À̸§°ú °ªÀÌ µé¾î°£´Ù´Â °ÍÀº ¾Õ¿¡¼ °øºÎ Çß¾úÁö¿ä?--; protected synchronized int[] getHitCountOnly(String filename) »õ·Î »ý±ä ¸Þ¼ÒµåÀÔ´Ï´Ù. À§¿¡¼ ¼³¸íÇßµíÀÌ ÀÌ¹Ì Cookie°¡ ¸¸µé¾îÁ®
ÀÖ´Â »ç¶÷Àº Count¼ö¸¦ ¿Ã¸± ÇÊ¿ä°¡ ¾øÀ¸´Ï, ±×³É ÇöÀçÀÇ Count°ªÀ»
ÀÐ¾î µéÀ̴µ¥ »ç¿ëÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù. ÀÌÀü nc.class¿¡¼ÀÇ getHitCount()
¸Þ¼Òµå¿Í´Â Å« Â÷ÀÌ°¡ ¾ø½À´Ï´Ù. ´Ù¸¸ °ªÀ» Áõ°¡½ÃÄѼ ´Ù½Ã file ¿¡
writingÇÏ´Â ºÎºÐ¸¸ ºüÁ® ÀÖ½À´Ï´Ù. protected synchronized int[] UpdateHitCount(String filename) ¿ª½Ã »õ·Î »ý±ä ¸Þ¼ÒµåÀÔ´Ï´Ù. ÇÏÁö¸¸ Â÷ÀÌ°¡ ¾ø³×¿ä. nc.class¿Í.
°ªÀ» ÀÐ¾î¼ Áõ°¡½ÃÅ°°í ´Ù½Ã ÀúÀåÇÏ´Â ³»¿ëÀ¸·Î µÇ¾î ÀÖ½À´Ï´Ù. ºÎ¿¬
¼³¸íÀÌ ÇÊ¿ä ¾ø°ÚÁö¿ä? protected Cookie getCookie(HttpServletRequest req, String
c_name) °¡Àå Áß¿äÇÑ ¸Þ¼Òµå°¡ µÇ°Ú³×¿ä. Cookie¸¦ ¾ò¾î³»´Â methodÀÔ´Ï´Ù.
parameter·Î´Â HttpServletRequest¿Í StringÀ» ¹Þ´Â±º¿ä. ÀüÀÚ´Â ¸»¾¸À»
¾Èµå·Áµµ Àß ¾Æ½Ç °ÍÀÌ°í, c_nameÀ̶ó´Â StringÀº ¹Þ¾ÆµéÀÏ CookieÀÇ
À̸§ÀÔ´Ï´Ù. ±×·¡¼ °°Àº À̸§ÀÇ Cookie¸¦ ã¾Æ¼ ±× Cookie¸¦ returnÇϵµ·Ï
ÇÕ´Ï´Ù. Cookie[] cookies = req.getCookies(); °¢°¢ÀÇ ºê¶ó¿ìÀú´Â ÇϳªÀÇ Cookie¸¸À» °¡Áö°í ÀÖ´Â °ÍÀÌ ¾Æ´Ï±â ¶§¹®¿¡,
¹Þ¾Æ¿À´Â Cookie´Â ¹Ýµå½Ã ¹è¿·Î ¹Þ¾Æµé¿©¾ß ÇÕ´Ï´Ù. ±×·¡¼ ¹Þ¾ÆµéÀÎ
CookieÁß¿¡¼ ¿øÇÏ´Â °ÍÀ» ã½À´Ï´Ù. ÄíÅ°ÀÇ À̸§ÀÌ °°Àº °ÍÀ» ÀǹÌÇÏ´Â
°ÍÀÌÁö¿ä. Cookie[] cookies = req.getCookies(); À§ ³»¿ëÀº Cookie°¡ ÀÖ´Ù¸é, ±× CookieÁß¿¡¼ À̸§ÀÌ °°Àº Cookie¸¦
ã¾Æ¼ return½Ãŵ´Ï´Ù. ¾î·ÆÁö ¾ÊÀ¸´Ï ´õ ÀÌ»óÀÇ ºÎ¿¬Àº ÇÊ¿ä ¾ø°ÚÁö¿ä? public void setCookie(HttpServletResponse res, String c_name) ÀÌ ¸Þ¼Òµå´Â ¹Þ¾ÆµéÀÎ c_nameÀ¸·Î Cookie¸¦ ¼³Á¤ÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
À̹ø¿¡´Â »ý¼ºÀ» ÇÏ´Â °ÍÀÌ´Ï ´ç¿¬È÷ HttpServletResponse °´Ã¼¸¦ ¹Þ¾Æ¼
ÇØ¾ß ÇÏ°ÚÁö¿ä? ±×·¡¼ Date date = new Date(); ÇöÀçÀÇ ½Ã°£À» ÀÌ¿ëÇؼ Cookie¸¦ res.addCookie(Cookie c)¶ó´Â
¸Þ¼Òµå¸¦ ÀÌ¿ëÇؼ »ý¼ºÇØ ÁÝ´Ï´Ù. ¾î·ÆÁö ¾Ê°Ô »ç¿ëÇÏ½Ç ¼ö ÀÖ°ÚÁö¿ä?
¿©±â¼, CookieÀÇ °ªÀ» ÇöÀç ½Ã°£À¸·Î Çߴµ¥, ÀÌ°É ÀÌ¿ëÇؼ »ç¿ëÀÚ¿¡°Ô
´ç½ÅÀº ¾ðÁ¦ ¿À¼Ì¾ú±º¿ä, ¶ó°í ¸»ÇÒ ¼öµµ ÀÖ°ÚÁö¿ä? ¶Ç´Â ¼ýÀÚ¸¦ ÀÔ·ÂÇØÁÖ¾î¼
¸î ¹ø° ¹æ¹®ÀÔ´Ï´Ù ¶ó°í ¸» ÇÒ ¼öµµ Àְڳ׿ä....*^^* service ¸Þ¼Òµå´Â Cookie°¡ ÀÖ´ÂÁö ¾ø´ÂÁö¸¦ È®ÀÎÇؼ ÀûÀýÇÑ ¸Þ¼Òµå¸¦
È£Ãâ ÇÑ ´ÙÀ½¿¡ ¹ÞÀº °ªÀ» ÀÌ¿ëÇؼ ȸ鿡 »Ñ·ÁÁÖ´Â ÀÏÀ» ÇÕ´Ï´Ù. ±×·³
Àß ¾Æ½Ã°ÚÁö¿ä?
If you have any question, send mail to bluehope |