ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


¼¼¼ÇÀ» ÀÌ¿ëÇÑ Ä«¿îÅÍ
13³â Àü
// sessionÀ» ÀÌ¿ëÇÑ Ä«¿îÅÍ
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionCounter extends HttpServlet
{
static final String Counter_key ="Counter.count";

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
  // Ŭ¶óÀ̾ðÆ®·Î ºÎÅÍ ¼¼¼ÇÀ» °¡Áö°í ¿À´Âµ¥.
  // true À϶§¸¸ ¼¼¼ÇÀÇ °´Ã¼¸¦ ¹ÝȯÇÕ´Ï´Ù.
  HttpSession session = req.getSession(true);

  res.setContentType("text/html");

  PrintWriter pout = new PrintWriter(
   new OutputStreamWriter(
    res.getOutputStream(),"KSC5601"
   )
  );

  int count =1;
  Integer i =(Integer) session.getAttribute(Counter_key);

  //¸¸¾à ±× Àü¿¡ Ä«¿îÅÍ°¡ ÀÖ´Ù¸é ±× °ªÀ» ´õÇØÁÝ´Ï´Ù.
  if( i != null)
  {
   count=i.intValue()+1;
  }//if ¹® ´Ý±â

  // ÄíÅ°°ü·Ã ½ÃÀÛ!!
  // »ç¿ëÀÚ¿¡°Ô ÀúÀåµÈ ÄíÅ°¸¦ ¸ùâ °¡Á®¿Â´Ù. ±×¸®°í ÀúÀåµÈ ½Ã°£µµ °¡Á®¿Â´ç..
  Cookie cookies[] = req.getCookies();
  Cookie cookie = null;
  long cookieDate = 0L;
  if(cookies != null)
  {
   cookie = cookies[0];
   cookieDate = Long.parseLong(cookie.getValue());
  }
  else
  {
   Cookie coo = new Cookie("TodayCheck", new String(""+System.currentTimeMillis()));
   coo.setMaxAge(60*60*24);
   res.addCookie(coo);
  }

  long nowTime = System.currentTimeMillis() - cookieDate;
  if(nowTime > 60*60*24*1000)
  {
   // ¿©±â Á¶±Ý ÀÌ»óÇÔ.. MilliSecond ¸¦ Áشٰí Çؼ­
   // 1000À» °öÇØÁÖ±â´Â Çߴµ¥ Á¤È®ÇÑÁö´Â ¸ð¸£°ÚÀ½.
   // API º¸°í ¼öÁ¤¿ä¸Á..
   System.out.println("ÇÏ·ç°¡ Áö³µ½À´Ï´Ù. Ä«¿îÆ®¸¦ Áõ°¡ÇÕ´Ï´Ù.");
   //»õ¼Ç¾È¿¡ ¹ÝȯµÈ Ä«¿îÅÍÀÇ °ªÀ» Ãß°¡ÇÕ´Ï´Ù.
   session.setAttribute(Counter_key, new Integer(count));
  }
  else
  {
   System.out.println("ÇÏ·ç°¡ ¾ÈÁö³µ½À´Ï´Ù. ´ç½ÅÀ» Áõ°¡´ë»ó¿¡¼­ Á¦¿ÜÇÕ´Ï´Ù~~(°³±×Äܼ­Æ®¹öÁ¯)");
  }
  // Cookie Ŭ·¡½º °ü·Ã ³¡... ½ÇÇàÇϽðí ÄíÅ°°¡ »ý¼ºµÇ¾ú´ÂÁö Cookie µð·ºÅ丮¿¡¼­ È®Àοä¸Á..

  pout.println("<html>");
  pout.println("<head>");
  pout.println("<title> ¼¼¼ÇÀ¸·Î ¸¸µç Ä«¿îÅÍ</title>");
  pout.println("</head>");
  pout.println("<body>");
  pout.println("´ç½ÅÀÇ ¼¼¼Ç¾ÆÀ̵ð´Â <b>"+session.getId()+"</b>");
  pout.println("ÀÌ¸ç ´ç½ÅÀÇ ¹æ¹®È½¼ö´Â <b>"+count+" ° ÀÔ´Ï´Ù.</b>");
  pout.println("<form method=GET action=""+req.getRequestURI()+"">");
  pout.println("<input type=submit value="´Ù½Ãº¸±â">");
  pout.println("</form>");
  pout.println("</body></html>");
  pout.flush();

}// doGet() ´Ý±â

}// SessionCounter´Ý±â
ÃßõÃßõ : 294 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,505
Java·Î ±¸ÇöÇÏ´Â °£´ÜÇÑ Client & Server ÇÁ·Î±×·¥
1,504
JDK ´Ù¿î·Îµå ¹× ¼³Ä¡ ¹æ¹ý
1,503
IIS¿¡¼­ JSP or Java Servlet µ¹¸®´Â ¹æ¹ý 1
1,502
ÅèĹ(Tomcat)ÀÇ ±â´É °³¿ä ¹× ¼³Ä¡ ¹æ¹ý
1,501
JSP ÆäÀÌÁö À̵¿ 4°¡Áö ¹æ¹ý ¹× Ư¼º
¼¼¼ÇÀ» ÀÌ¿ëÇÑ Ä«¿îÅÍ
1,499
ÆÄÀÏ¿¡¼­ ÇÑÁÙ¸¸ Àоî´Ù return ÇØÁÖ´Â ¼Ò½º
1,498
À¥ÆäÀÌÁö ±Ü¾î¼­ ŸÀÌƲ »Ñ·ÁÁÖ´Â ¼Ò½º
1,497
¾î¶² ÆĶó¸ÞÅÍ°¡ ³Ñ¾î¿Ô´ÂÁö ¾Ë¾Æ³»´Â ÇÔ¼ö
1,496
À½·Â-¾ç·Â º¯È¯±â
1,495
OpenSSL Example PHP Code - VerifySignature
1,494
Á¤¼ö ¿¬»ê½Ã ¹«Á¶°Ç ¿Ã¸², ¹«Á¶°Ç ¹ö¸², ¹Ý¿Ã¸² ó¸® ¹æ¹ý
1,493
À̹ÌÁö¸¦ ÁöÁ¤µÈ ºñÀ²·Î ÀÚ¸£±â (crop)
1,492
ÁöÁ¤³¯Â¥¿¡ À̹ÌÁö º¸¿©ÁÖ±â ȤÀº °¨Ãß±â
1,491
ÃÊ°£´Ü php-oracle ¿¬µ¿ Ŭ·¡½º
1,490
¼ÒÄÏÀ¸·Î ¸ÞÀϺ¸³»±â
1,489
escape(), unescape() - ¹®ÀÚ ¾Ïȣȭ
1,488
³»¿ëº¹»ç½Ã Ãâó ÀÚµ¿³Ö±â
1,487
´ë¹®ÀÚ, ¼Ò¹®ÀÚ º¯È¯ ÇÔ¼ö
1,486
PHP, Á¤±ÔºÐÆ÷ ³­¼ö »ý¼º, °¡¿ì½º ºÐÆ÷ ·£´ý ¹ß»ý ÇÔ¼ö; Normal Distribution
1,485
¸Å¹ø rand°á°ú°¡ °°°Ô ³ª¿ÀÁö ¾Ê°Ô ÇÏ·Á¸é
1,484
UTF-8·Î ÀÎÄÚµùµÈ ¹®ÀÚ¿­À» EUC-KR·Î ¹Ù²Ù´Â ¹æ¹ý
1,483
PHP¿¡¼­ URL Open½Ã ¿¡·¯°¡ ³¯¶§
1,482
Flash¿Í PHP¸¦ È°¿ëÇÏ¿© ¸ÖƼ ÆÄÀÏ ¾÷·Îµå ±¸ÇöÇÏ´Â ¹æ¹ý
1,481
mysql ¹é¾÷¿¡¼­ º¹±¸±îÁö
1,480
ƯÁ¤ ¹®ÀÚ¿­À» ±âÁØÀ¸·Î Çؼ­ ¹è¿­·Î ¸¸µé¾îÁÖ´Â ¹æ¹ý
1,479
Á¤±Ô½ÄÀ¸·Î ¹®ÀÚ¿­ ¹Ù²ãÁÖ±â
1,478
ƯÁ¤ Æ÷Å»¿¡¼­ Á¢¼ÓÇÑ »ç¿ëÀÚ¸¸ Á¢¼Ó ¸·´Â ¹æ¹ý
1,477
¹®ÀÚ¿­(string)À» ¹è¿­(array)·Î ¸¸µé¾îÁÖ´Â ¹æ¹ý
1,476
IP Address·Î ±¹°¡ ¾Ë¾Æ³»´Â ¹æ¹ý
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.