• 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

Cancel request mechanism

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ..?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cancel button for what? to cancel the request?
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

seetharaman venkatasamy wrote:Cancel button for what? to cancel the request?

ya cancel the request
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can cancel the submit via javascript by returning false in an event, so the request doesn't reach the server.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ..
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic