모바일웹/쿠키 설정관련

JSP 쿠키를 이용한 방문자 count

nineDeveloper 2015. 3. 31. 15:58
728x90
반응형
<%@ page contentType="text/html;charset=utf-8" %>
<html>
<head><title>로그인</title></head>
<%
   Cookie countCook = new Cookie("countCook", "count"); 
    
     
   String ValuelnCookie;
   int count = 1;
   boolean isIDShow = false;
   String id = null;
   Cookie[] cookies = request.getCookies();
      if (cookies != null && cookies.length > 0) {
         for (int i = 0 ; i < cookies.length ; i++) {
      
if (cookies[i].getName().equals("id")) {
                      isIDShow = true;
                      id = cookies[i].getValue();
                  }
    
                            
else {
ValuelnCookie = countCook.getValue();
   count = Integer.parseInt(ValuelnCookie);
            count ++;
ValuelnCookie = Integer.toString(count);
countCook.setValue(ValuelnCookie);
countCook.setMaxAge(10);
countCook.setPath("/");
response.addCookie(countCook); 
         
}
}
}
%>

<body>
관리자 (Master)로 로그인하세요.<br/>

<form action="loginProcess2-lab7.jsp" method="post">
<%
   if (isIDShow) {
%>
ID : <input type="text" name="id" value="<%= id %>">
<input type="checkbox" name="idstore" value="store" checked>아이디 기억하기
</input><br/>
<%
   } else {
%>
ID : <input type="text" name="id">
<input type="checkbox" name="idstore" value="store">아이디 기억하기</input><br/>
<%
   }
%>
Password : <input type="password" name="pw"><br/>
<input type="submit" value="전송">
</body>
</html>


728x90
반응형