This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes sendRedirect() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sendRedirect()" Watch "sendRedirect()" New topic



Joined: Jan 29, 2003
Posts: 7
Does using sendRedirect() end a session, if so how to retain the same session
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
no, it does not.
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Hi Venkatesh
A session is started when the first request is received from a client, and ends when the same client explicitly ends the session or the server does not receive any further requests from the client for a certain period of time (which can be configured in the web.xml file). The servlet itself can also invalidate a session itself using HttpSession.invalidate().
sendRedirect() merely directs the client to another resource. It does commit the response to the client, but it does not end the session itself.
[ January 29, 2003: Message edited by: mark howard ]

Joined: Jan 29, 2003
Posts: 7
can we use pageContext.getOut().print("Hi") in doAfterBody() method.

Joined: Jan 29, 2003
Posts: 7
thanks Howard and Boyet
Sudd Ghosh
Ranch Hand

Joined: Oct 23, 2002
Posts: 187
Hi Venkatesh -
Yes, in the doAfterBody() method you can use the getOut() method on the PageContext object that you've already saved using the setPageContext(). Pls note you don't have the implicit variable pageContext available in the tag handler class. It seems whatever you can do in doStartTag() can be done in doAfterBody(), however in the case when some body-content is present, the calling sequence will differ.
Thanks, Sudd

jQuery in Action, 3rd edition
subject: sendRedirect()
It's not a secret anymore!