Show TOC Start of Content Area

Procedure documentation Retrieving Cookies from the HTTP Request  Locate the document in its SAP Library structure

Use

Use the HTTP request object that is passed to the service method of your servlet to get all cookies that the client browser sent with the request.

Procedure

...

       1.      Use the getCookies() method of the HttpServletRequest to retrieve an array of all cookies in the request.

       2.      Loop down the array entries calling getName() on each Cookie object until you find the cookie you want to retrieve.

       3.      Call the getValue() (or any of the other methods that javax.servlet.http.Cookie class defines to retrieve other parameters) on that object to get the value of this particular cookie.

Syntax

Cookie[] cookies = request.getCookies();

String cookieName = SAPCookie;

String defaultValue = 1;

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

      Cookie cookie = cookies[i];

      if (cookieName.equals(cookie.getName()))

        return(cookie.getValue());

    }

    return(defaultValue);

  }

Result

You have retrieved cookies that the client browser sent with the request.

 

End of Content Area