Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

sendRedirect (), forword ()

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic