I have designed a website using servlets which enables them to shop and chat. i have an administrator account for this site which allows me to get disable a user account.. Supose this user is online at the moment. I want him to be redirected immediately to an error message. For this When they login i am storing their response object into a static vector. Now i am able to get hold of this response object but am unable to redirect the user to the error page. I am not getting any errors though. please help me out - Prashant
I may be misunderstanding you, but I think what you need to do is store a value in the session object and upon the user sending a request to your site, check this variable and then perform your redirect. You cannot redirect a user after they have received a previous response because the browser closes communication. So, you must wait for them to send another request. David Sun Certified Programmer for the Java2 Platform
Hi Prashant, The response object is valid only for a particular interaction with the server. It is not same across the entire session. If the user does not make a request to your servlet/JSP page, you will not be able to get the response object, then there is no way you can redirect him to another page. This is because HTTP is a stateless protocol and does not remember interaction history with the server. The browser makes a different connection with the server for each request. But, you can always trap all requests and check each time whether the user account is enabled/disabled and decide the course of action. Hope this helps. Ashwin.
Firing from the hip, it seems like you might be able to do it with an applet on the client side, but if it is just their browser then you must wait for another request before they will get any message. I haven't tried to do it or thought it through, but it seems like an applet could respond in real time (connection speed time) to the session invalidate() or something similar.
Hi Prashant, I have designed an login/logout JSP site and had a requirement very similar to yours.I was storing the valid (not disabled) users in the application implicit object.When the user is disabled, the user entry is removed from the application object. There is a check at the start of my every JSP page, which checks if the user is valid or not.Only if his id is enabled, he is allowed access to the page. If not, he is forwarded to an error page. I have used the <jsp:forward> tag for this purpose. Hope this helps. Regards,
Originally posted by prashant sreenivasan: Thank you all for your replies.. What you all say is correct.. but is there any way of redirecting the user without him requesting another page.. Prashant
I would invalidate the session in your static storage. It would allow you to force the user to the error page on the next request. You can't determine if the user is still reading the page or has closed his browser.