• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect (), forword ()

 
deepak bansal
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am facing a problem regarding the sendRedirect() and forword() .
I want to use both of them in my servlet method in the doPost() method . I am doing following two things in the doPost method of servlet in this order---->
1)First i am using the senRedirect() Method to send the request to a servlet to Invalidate the Session.
2)I am displaying a jsp page to the browser using the forword method.
The problem is that session is getting invalidated properly but its giving the IllegalStateException when it comes to the forward method.
Thanks
Deepak
------------------
Be Truthful to yourself!
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you invalidate the Session on the fly?
I don't think sendRedirect() forwards anything to the destination URL. Sure you could use GET parameters when building the URL but, the request will not be forwarded as in forward().
Probably the Request is terminated when you execute sendRedirect().
The API says "After
using this method, the response should be considered to be committed and should not be written
to."


I'd like to see what other have to say...
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, Tony. In a single doPost() method it's "either/or" not "both and".
Kyel
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
deepak bansal
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Both,
My problem is that i am working in the clustered environment and if the same person logins from the different machine i have to kill the previous session .I am stroring the information into the database as user logins first time and using this if he logins agains. In the single login method i am using the sentRedirect method to send the request to a InvalidateServlet which kills the session (Even the previous session is in the different machine in the cluster environment).I want the Control back to my login function to show the user desitrable page(Using the forward method).
Thanks & Regads
Deepak
------------------
Be Truthful to yourself!
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isnt going to work - sendRedirect sends a response to the Client (the actual browser) asking them to send a new request to the InvalidateServlet. There is no way that you will be able to sensibly re-use the initial request by further processing. If you do manage to get this to work, you will have all kinds of thread safety problems.
You should probably do this in your business logic layer, not servlet for this functionality.
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak - I think I have a solution for you. Why not do two forwards, instead of doing a redirect? All you have to do is pack your final destination page/servlet name using req.setAttribute( "finalJSP", "myJSP.jsp" ), forward to InvalidateServlet, invalidate the session, then have InvalidateServlet forward to req.getAttribute( "finalJSP" ). How are you detecting that a user has a session on a different machine? Or are you just attempting to kill any that exist for that user when a new session is created? Good luck!
 
deepak bansal
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gerry/James,
I cannot use the forward twice because i am sending the request to different machine in the cluster .forward method can be used only within the context of the servlet .So i have to use the sendRedirect(). As faor as the session infromation is concern i am keeping it into the database.
Thanks & regadrs
Deepak
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic