[EMAIL PROTECTED] wrote:
> How can I grab the cookies from a URLConnection and
> forward it to via my servlet to a client browser?
>
I assume you're talking about reading the *output* cookies from a request that
your servlet made to some other resource, right?
>
> //grab cookie from a URLConnection
> URLConnection uc;
> String name =uc.getHeaderFieldKey("????"); //?????
> String value =uc.getHeaderField("????"); //?????
>
> // how can I know that I am getting all the cookies??
> // how can I know which ones are session tracking??
> // (Session-Id) is this standard??
> //
>
In order to understand HTTP headers and values, you need to read the
appropriate specification documents. In this case, the right spec is RFC 2109
(HTTP State Management Mechanism), which tells you the HTTP header name sent
by a client is 'Set-Cookie'. RFCs are available at
http://www.rfc-editor.org
Note that there can be more than one "Set-Cookie" header in a particular
request, if more than one cookie is being sent. You will want to use the
indexed versions of the getter routines -- something like this:
int n = 0; // Doesn't say for sure that indexes are zero relative
while (true) {
String key = uc.getHeaderFieldKey(n);
if (key == null)
break;
if (key.toUpperCase().equals("SET-COOKIE")) {
String value = uc.getHeaderField(n);
// Cookie encoded in this string per RFC 2109
// You will need to extract all the parameters to
// set up a Cookie object that looks like this one.
}
n++;
}
Session cookie names are not currently standardized, but will be when servlet
engines implement the servlet API version 2.2 specification, at which point
the required name will be "jsessionid".
>
> Cookie c= new Cookie("name","value");
> (HttpServletRequest) req.addCookie();
>
> Calvin
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html