• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Doubt in Cookies

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

If I set cookies in a response & then call response.sendRedirect("url"), will the cookie be sent across to that particular url?

Is there any way we can force the cookie to be sent to that url?

Please assume that the browser's cookie handling mechanism is enabled, ie, the browser does accept cookies.

If the above is not possible, then how to handle such a scenario where we need to do a redirect to another application & also need to send a little extra info for specific processing in that application.

Thanks & Regards,
Sourin.
 
Sourin K. Sen
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone?
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sourin ,

Do you find any answer for this ?

Let me know.

Thanks,
Amol
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
response.encodeRedirectURL(String url)
Is this work for your scenario?
[ June 13, 2008: Message edited by: Anand Bhatt ]
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes It will certainly set the cookie.
How ? ok will give you simple example:

Let say Authentication servlet we check user's credential and if sucessful we create session and send it to mypage.jsp otherwise on login.jsp.

On my page.jsp we are checking the session if created we display all details else redirect to login.jsp.

so it will be like

NOW If you check in mypage.jsp ${id} it will print the user id.

You might be thinking why i described this whole story..instead of to the point answer.
Because you can think this way when you get questions whose exact answer you dont now but you have to logically derived.

See req.getSession() will check for session obiously first time it will not get and it create new session and set its cookie in response (JSESSSIONID).

So on mypage we are getting session 's attribute.Means even if you do res.sendRedirect() your cookie will be taken cared.
 
Sourin K. Sen
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I guess I couldn't come back to this topic once I found the reason behind this problem and its kinda a little late right now, but here goes ...

My problem was, I was trying to send the cookie from an SSL application to a non-SSL application. While doing so, what we must keep in mind is that the domain name of both the url's should be same otherwise the cookie will not be sent across.

However, if both the url's are working on non-SSL and the domains are different, the cookie can be sent over from the first url to the second. This should hold true even for two url's working on SSL but having different domains although I haven't tested it yet.

In short, the problem of cookie not getting tranferred arises only when the control goes from SSL to non-SSl or vice versa.

If we require that data be sent across from SSL to non-SSL where the domain names are different, then the option of cookies cannot be used. In such a case, other modes of data transfer needs to be applied for ex : Url Rewriting, SOAP, etc...
[ July 16, 2008: Message edited by: Sourin K. Sen ]
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic