• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Session is not preserverd whn sendRedirect is used ???

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

Guys i found the following quote in one of the forums, and am not convinced with this statement, let me know if this is true, plzz

When you forward the request with requestDispatcher.forward the target servlet/JSP share the same session. But with sendRedirect the session information is not preserved. ( target is not in scope of session)



-Tripter
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,


No that statement is wrong as my knowledge goes.
i have worked with the servlets and used the sendredirect mechanism, and the session info is preserved there, im able to get the session object from there also


regards,
aadi
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I am aware it is wrong. The only condition I can think where it may be correct is the situation where the sendRedirect is the response to the first request, and this response is also the one trying to set the session cookie. I'm not convinced but it may be possible.

eg.


In this case the instruction either may not be sent or accepted and hence the session would not be created , but but I'm not sure, and I'm not convinced.

Like I said, sounds wrong.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like a typo error. It seems that the para refers to the requst scope rather than session.
 
Srivatsa Katta
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for sharing your views guys!!

-Tripter
 
Ranch Hand
Posts: 1026
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I see where the confusion is coming from. The quote is not correct, or in the very least worded very badly. But I think I understand what the author was trying to get at.

If you use sendRedirect to redirect the user to a different context, i.e. a different application, of course the session information is not preserved. It would be meaningless because sessions are tied to a specific context. (for example, my session information from javaranch would have no meaning if I decided to go to yahoo)

However, using sendRedirect within the same context works perfectly. The author of the previous quote mistakenly implies that sendRedirect is only used when changing contexts, however, this is not the case. There are times when it is advisable to redirect within the same context. For example, if you need to send the user to a new page, but wanted to maintain the previous page's URL inthe browser cache.
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another case when the redirect is to switch to different protocol http to https.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



if you need to send the user to a new page, but wanted to maintain the previous page's URL in the browser cache.




Don't you think for this you need to go for RequestDispatch rather than sendRedirect?
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you think for this you need to go for RequestDispatch rather than sendRedirect?

My mistake (early morning here ) I should have said "if you need to send the user to a new page, and wanted to maintain both the previous page's URL and the new page's URL in the browser cache."
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Another case when the redirect is to switch to different protocol http to https.



What would happen in above situation - sendRedirect() to same context but changing to ssl. I dont know about SSL much but its seems that it has some built-in facility to identify clients. And in that a case, a newly created SSL session should be considered as some new session. Am I right?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic