• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Cookies from Servlets sendRedirect

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No takers here, so I moved this to the Servlets forum.
 
Slime does not pay. Always keep your tiny ad dry.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic