When you communicate with a servlet from an Applet or an application, how can you ensure that the session information is preserved? That is, how do you manage cookies in applet-servlet communication?

John Zukowski

For sessions, your best bet is to have the servlet rewrite the URLs to include the session information. With cookies read I am writing an application that retrieves a URL, but that URL requires a cookie. Is there a way to hold that cookie within my application and send it back to the URL when requested? Essentially, you can send the cookie back easily with HTTP. For instance, urlConnection.setRequestProperty("cookie",_cookie); Where the _cookie is coming from a previous call: String _cookie = urlConnection.getHeaderField("set-cookie");

See also: