| Author |
Cancel request mechanism
|
Sherif Shehab
Ranch Hand
Joined: Mar 05, 2007
Posts: 472
|
|
Hi guys,
i wanna add a Cancel button to my jsp so it can cancel the request after submitting it to the server , Can anyone help me to reach the optimum mechanism to achieve this ..?
|
Thanks,
Sherif
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Cancel button for what? to cancel the request?
|
 |
Sherif Shehab
Ranch Hand
Joined: Mar 05, 2007
Posts: 472
|
|
seetharaman venkatasamy wrote:Cancel button for what? to cancel the request?
ya cancel the request
|
 |
Eduardo Bueno
Ranch Hand
Joined: Jun 04, 2009
Posts: 154
|
|
|
You can cancel the submit via javascript by returning false in an event, so the request doesn't reach the server.
|
 |
Sherif Shehab
Ranch Hand
Joined: Mar 05, 2007
Posts: 472
|
|
Eduardo Bueno wrote:You can cancel the submit via javascript by returning false in an event, so the request doesn't reach the server.
this in case the request hasn't submitted yet , what i wanna to cancel the request after submitting it the server ..
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
|
|
What sort of process did the first request start, that you now want to cancel it?
You could use the "cancel" request to set a flag in the session but interfering with the Thread handing the first request depends on what it is doing.
Bill
|
Java Resources at www.wbrogden.com
|
 |
Sherif Shehab
Ranch Hand
Joined: Mar 05, 2007
Posts: 472
|
|
William Brogden wrote:What sort of process did the first request start, that you now want to cancel it?
You could use the "cancel" request to set a flag in the session but interfering with the Thread handing the first request depends on what it is doing.
Bill
the process is getting some data from the db . what i wanna is to interfere the 1st request thread and cancel it .
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
|
|
How about this:
In the session object there is a boolean "cancel" flag initially set false
1. request A thread creates the data base query but does not execute it directly
2. instead, it creates a new Runnable object which will do the request and starts it
3. request A thread now sleeps X milliseconds
4. request A thread wakes up, looks at the Runnable object to see if the database request is done, if so go to 8
5. if not, check a flag in the session to see if it has been cancelled
6. if cancelled, complete the HTTP request - will have to provide some way for the Runnable object to eventually recover and clean up all objects created for the database request
7. if not go to 3
8. recover the retrieved data from the Runnable object, format and complete the request.
Your cancel request sets the session cancel flag to true.
Bill
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
If the database operation warrants that a cancel button be placed on the page, then I really doubt if such an operation belongs on the servlet. William's approach should work but it will likely waste a lot of thread resources on the server. Also, you will have to come up with a way to send a response, but keep threads on the server alive that will monitor the activity of the request made. And what happens when the user logs out and the session is lost ? Can your code handle that ?
If you are looking to say deliver a report using POI or something like that, it will make sense to move to a batch like process.
The request will be made and saved to a DB. A batch process picks up the request and processes the data. The results are saved in a table / file and the batch process sets a flag to denote this.The web app meanwhile displays a message to the user that the process is taking place and the user can check back sometime later.If the user wants to cancel, set a flag in the db. The batch process should read this flag at some stage of the processing and decide what to do.If the web app detects the flag denoting that the batch process is done, it display the data / file.
Can you provide more details about the operation to be performed. We can provide better answers if we know what problem you are trying to solve.
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
 |
|
|
subject: Cancel request mechanism
|
|
|