File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Session corruption........ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session corruption........" Watch "Session corruption........" New topic
Author

Session corruption........

Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai All!

Here is my problem... I have a form ..If i click submit button in that form request is generated and it is processed by server side component. This process includes reading and modifying an object stored in the session object. Problem is when user clicked submit times multiple times (quickly) some 3to 4 requests are generated and all requests is trying to modify object stored in session object and object is getting corrupted.
I need some solution this.. I don't want to disable submit button as i have some GUI desing restrictions. Also i don't want to use synchronize blocks as they tend to slow the program..What i need is some sort of terminating those extra requests generated. Is it possible to do so? if so how can we accomplish this and what are side affects of this?
If only solution is going to Synchronize blocks then pls suggest how best we can do it as the server compoent under consideration cannot be afford to be slowed down due to some real time considerations..
Any suggestions are most welcome..
TIA
Rgds
Manohar
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This problem is discussed in Core J2EE Patterns (I can't find a link at the moment). I can't remember what they suggest, but these might help...
If you use a Model-View-Controller pattern with a global controller, you can use a "current page" concept to ignore the fact that they submitted the form twice since you know they shouldn't be there.
You can also use a form tag - write a hidden value to the form with a unique value for that user, if you receive the key twice then you can ignore it.
Dave
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai!
Thanks for ur reply...I followed that approach..We are following MVC pattern and is not processing the request if same request is already under processing.
In JSP i am using custom Tag Handlers so that they process the display content and write back to JSP writer...
In case of multiple requests (As i explained above..) that writing to browser is throwing exception :
java.net.SocketException...
Any help is appreciable..
Rgds
Manohar
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

If the request is taking too long, the browser has to wait till something gets returned before it can change its display. When this is a long time, the user sometimes presses the submit button again.
When this happens, the browser breaks the connection to the server and starts again. The server can't tell this has happened till it tries to write to the browser, finds that the connection it was expecting doesn't exist, then throws the exception.
Meanwhile, the second request continues.
What I like to do (apart from making the processing more efficient) is to throw up a temporary "Please wiat" page while waiting for the server to respond.
Rather than having the first page submit to your processing, it submits to a dummy page that returns a "please wait" message, embeds the form data as hidden fields and auto-submits the data to the "real processing" page. This request takes a while, but the user has a nice page to view and can't press the button again.
Does this help?
Dave.
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai!
Idea is nice...But is it possible to do something without touching the pages..Like to try it on server side..
Rgds
Manohar
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Not really, cos as soon as they hit the submit button again the browser kills the old connection. The only other semi-acceptable way is to have a javascript flag in the page that gets set a stops the submit button from working. (this solution has a bunch of problems as well)
Looks like you might have to have another look at the processing being done and solve the problem from that point...
Dave.
(just for the record, I have to leave for the day. I hope you get your problem solved )
[This message has been edited by David O'Meara (edited December 04, 2001).]
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai All!

This is more or less repetition of my previous query,,I cannot change my pages due to some cinsiderations.. Now is there anyway i can handle the situation of multiple requests?
RGds
Manohar
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227

Like is there anyway to know that connection is terminated as soon as it is terminated?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

No. HTTP is stateless.

your server side is completely and blissfully un-aware of what is going on at the client.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

OK, a solution I came up with just after walking out the door is this:
(this will only solve the problem with ppl pressing the submit button, it won't stop them reloading etc.) I'd also like to say I don't like this solution and I'm not positive it will work, but I can't think of a reason why not...
As soon as your Servlet begins, send some white space down the InputStream and flush it. (send a bunch of spaces of carriage returns) This should clear the page at the client side so they can no longer press the submit button.
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session corruption........