title: Cookies generating some random values
body: <p>jsp file   </p>
  
  <pre><code>&lt;% 
  
                 String stateforcookie=request.getParameter("stateforcookie");
                 if(stateforcookie != null ) {
                 Cookie cookies2 = new Cookie("statecookie",stateforcookie);
  
                 cookies2.setMaxAge(365 * 24 * 60 * 60);
                 response.addCookie(cookies2);
                 }                  
                 String state=request.getParameter("state");
                 Cookie[] cookies2=null;
                 cookies2 = request.getCookies();
                 out.print(cookies2);
  
                 if (state==null) { if(cookies2 != null)
                                      state=cookies2[0].getValue(); }
                if(cookies2[0].getValue() == null) {
                 %&gt;
  
  &lt;body onload="po(0);"&gt;
  &lt;% }else { %&gt;
  &lt;body onload="po(1);"&gt;
  &lt;% } %&gt;
  
  &lt;div id="popup"&gt;
  &lt;div id="contenttt"&gt;
  &lt;form method="post" action="home.jsp"&gt;
  Choose Your State:&lt;input id="popuptext" type="text" name="stateforcookie" /&gt;
   &lt;input id="popupclose" type="submit" value="submit" /&gt;   
  &lt;/form&gt;
  &lt;/div&gt;      
  &lt;/div&gt;
  </code></pre>
  
  <p>javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;  
  function po(i) {
  
   if(i==1){
   $('#popup').hide("slow");
      }
    else if(i==0){$('#popup').show("slow");}
  }
  $(function(){   
       $('#popupclose').click(function(){
  
          $('#popup').hide("slow");
  
      });
  
  });   
  &lt;/script&gt;
  </code></pre>
  
  <p>1.Here i'm trying to store a value to cookie, if cookie is null it will popup a window with text box. if the cookie is not null then the popup window will not been shown.</p>
  
  <p>But i'm facing a problem with the line - out.print(cookies2);  It prints:- </p>
  
  <blockquote>
    <p>[Ljavax.servlet.http.Cookie;@1d6bff7</p>
  </blockquote>
  
  <ol>
  <li>if(cookies2[0].getValue() == null) throws null pointer Exception.. 
  Even after deleting all browsing data, i'm getting the same error</li>
  </ol>