File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Cookies from Servlets sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookies from Servlets sendRedirect" Watch "Cookies from Servlets sendRedirect" New topic
Author

Cookies from Servlets sendRedirect

Karthik Prabu
Ranch Hand

Joined: Dec 27, 2002
Posts: 48
Hi All,
I am using HttpUrlConnection to get connect and get rexponse from a servlet. Since i need to handle redirection I am handling it myself. But the cookies set to the Response in the servet b4 redirecting is not available in my client. is there any to get this on the clinet. But bi am getting the JSESSIOn cookie which is created by the server. Following is the code snippet
URL serverUrl = new URL(url);
HttpURLConnection con = (HttpURLConnection)serverUrl.openConnection();
con.setDoOutput(true);
con.setDoInput( true );
con.setRequestMethod("POST");
con.setFollowRedirects( false );
while( true ){
statusCode = con.getResponseCode();
//System.out.println( statusCode );
if( statusCode == 302 ){
String location = con.getHeaderField("Location");
System.out.println( location );
// Only JSESSION cookie is retunrned...and not my own cookie
String cookie = con.getHeaderField("set-cookie");
URL u = new URL( location );
con.disconnect();
con = ((HttpURLConnection)u.openConnection());
con.setFollowRedirects( false );
con.setRequestMethod("GET");
con.connect();
continue;
}
break;
}

Thanks in Advance
Saran
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

No takers here, so I moved this to the Servlets forum.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies from Servlets sendRedirect