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

¼¼¼ÇÀ» ÀÌ¿ëÇÑ Ä«¿îÅÍ
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´Ý±â
ÃßõÃßõ : 269 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,885
input ÀÔ·Â ÇÊµå ¾ÕµÚ °ø¹é ½Ç½Ã°£ Á¦°Å
2,884
Placeholder Æ÷Ä¿½º½Ã °¨Ãß±â
2,883
MySQL Áߺ¹µÈ µ¥ÀÌÅ͸¦ »èÁ¦
2,882
MySQL Áߺ¹ µ¥ÀÌÅÍ È®ÀÎ
2,881
sessionStorage.getItem ¿Í sessionStorage.setItem
2,880
Á¦ÀÌÄõ¸® ·£´ýÀ¸·Î ¹è°æ»ö º¯°æ
2,879
preg match¿¡ °üÇÑ Á¤±Ô½Ä
2,878
Stream an audio file with MediaPlayer ¿Àµð¿À ÆÄÀÏ ½ºÆ®¸®¹Ö Çϱâ
2,877
Audio Streaming PHP Code
2,876
PHP $ SERVER ȯ°æ º¯¼ö Á¤¸®
2,875
Vimeo (ºñ¸Þ¿À) API ¸¦ »ç¿ëÇÏ¿© Ç÷¹À̾î ÄÁÆ®·ÑÇϱâ
2,874
iframe »ç¿ë½Ã ÇÏ´Ü¿¡ ¹ß»ýÇÏ´Â °ø¹é Á¦°Å¹æ¹ý
2,873
¾ÆÀÌÇÁ·¹ÀÓ(iframe) Àüüȭ¸é °¡´ÉÇÏ°Ô Çϱâ
2,872
ºÎÆ®½ºÆ®·¦(bootstrapk)¿¡¼­ »ç¿ëÇÏ´Â class¸í Á¤¸®
2,871
ºÎÆ®½ºÆ®·¦ CSS
2,870
Å©·Ò¿¡¼­ ¸¶Áø Á¶Àý
2,869
PHP ÇöÀç ÆäÀÌÁöÀÇ µµ¸ÞÀθíÀ̳ª urlµîÀÇ Á¤º¸ ¾Ë¾Æ¿À±â
2,868
PHP preg match all()
2,867
PHP ·Î À¥ÆäÀÌÁö ±Ü¾î¿À±â ¸ðµç ¹æ¹ý ÃÑÁ¤¸®!
2,866
[PHP] ¿ø°ÝÁö ÆÄÀÏ ÁÖ¼Ò ³ëÃâ ¾ÈÇÏ°í curl·Î ´Ù¿î·Îµå ¹Þ±â
2,865
PHP ÇÔ¼ö Á¤¸®
2,864
¾ÆÀÌÇÁ·¹ÀÓ(iframe) ºñÀ² À¯ÁöÇϸ鼭 Å©±â Á¶ÀýÇÏ´Â ¹æ¹ý
2,863
PHP ¹è¿­¿¡¼­ ¹«ÀÛÀ§·Î Çϳª »Ì¾ÆÁÖ´Â array rand() ÇÔ¼ö
2,862
PHP Á¤±Ô½Ä Á¤¸®
2,861
PHP Á¤±Ô½ÄÀ» È°¿ëÇÑ ÅÂ±× ¹× ƯÁ¤ ¹®ÀÚ¿­ Á¦°Å ¹× ÃßÃâ ¹æ¹ý
2,860
php Å©·Ñ¸µ ¶Ç´Â ÆÄ½Ì ÇÔ¼ö, Á¤±Ô½Ä ¸ðÀ½
2,859
Á¦ÀÌÄõ¸® ±âº» ¸í·É¾î
2,858
À¥ÆäÀÌÁö °¡·Î ¸ðµå¼¼·Î ¸ðµå ÀνÄÇϱâ
2,857
¸ð¹ÙÀÏ À¥ È­¸é °­Á¦ ȸÀü(°¡·Î¸ðµå °íÁ¤)
2,856
[HTML5]¿¡¼­ frameset ´ëü ¹æ¹ý°ú iframe ¼Ó¼º
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.