title: cookie is adding twice in browser when page is loaded
body: <p>am guys am checking cookie is exist or not using Spring Handler interceptor pre-handle method. if the cookie is not present am sending the user to login using response.sendRedirect. if cookie is present am returning true and am resetting cookie time means deleting and adding same cookie</p>
  
  <pre><code>public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  throws Exception {
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          InputStream stream = classLoader.getResourceAsStream("bimspring.properties");
          Properties properties = new Properties();
          properties.load(stream);
          String cookieName = properties.getProperty("cookieName", "No Value Found");
          Cookie[] cookies = request.getCookies();
          String rememberMeCookieValue = null;
          if (cookies != null) {
              for (Cookie cookie : cookies) {
                  if (cookie.getName().equalsIgnoreCase(cookieName))
                      rememberMeCookieValue = cookie.getValue();
              }
          }
          try {
              if (rememberMeCookieValue == null) {
                  response.sendRedirect("http://localhost:8080/bimspring/");
                  return false;
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          return true;
      }
  </code></pre>
  
  <p><strong>jsp</strong></p>
  
  <pre><code>&lt;% 
   String myCookie = ""; 
          Cookie[] headercookies = request.getCookies();
           for(int i = 0; i &lt; headercookies.length; i++) { 
              Cookie c = headercookies[i];           
              if (c.getName().equals("myCookie")) {
                  myCookie = c.getValue();
          }   
          } 
  %&gt;  
  &lt;%
          if (myCookie.equals(loginWithRememberME)) {
  
              for (Cookie ck : request.getCookies()) {
                  if (ck.getName().equalsIgnoreCase("myCookie")) {
                      ck.setMaxAge(0);
                      response.addCookie(ck);
                  }
              }       
               Cookie rememberMeCookie = new Cookie("myCookie", loginWithRememberME);
                 rememberMeCookie.setMaxAge(Integer.parseInt(cookieAgeWithRememberME)); 
                 response.addCookie( rememberMeCookie ); 
              } 
      if (myCookie.equals(loginWithoutRememberME)) {
  
       for (Cookie ck : request.getCookies()) {
              if (ck.getName().equalsIgnoreCase("myCookie")) {
                  ck.setMaxAge(0);
                  response.addCookie(ck);
              }
          } 
       Cookie unRememberMeCookie = new Cookie("myCookie", loginWithoutRememberME);
                     unRememberMeCookie.setMaxAge(Integer.parseInt("500")); 
                     response.addCookie(unRememberMeCookie );
              }
      %&gt;
  </code></pre>