0 Replies Latest reply on Jul 6, 2012 9:59 AM by Smitha Dsouza

    delete cookie is adding a new cookie

    Smitha Dsouza Newbie

      this is my code where i am trying to remove a already added cookie.

      what is happening is it is adding a new cookie than updating a existing cookie...

         LOGGER.debug("========Entering removeMyViewedHotel(MyViewedHotelVo myViewedHotel)===========");

            //getting the cookies

              HttpServletResponse res =

                      (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()

                              .getResponse();

              HttpServletRequest req =

                      (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()

                              .getRequest();

              Cookie[] cookies = req.getCookies();

              if(cookies!=null){

                  for(int i = 0; i < cookies.length; i++){

                      if(cookies[i].getName().equalsIgnoreCase("cookieKey-"+myViewedHotel.getViewedAccomoId())){

                          cookies[i].setMaxAge(-1);  

                          req.addCookie(cookies[i]);

                      }

                  }

              }