control thread using javascript button in jsp
how to control threads in a jsp page using javascript button?
when i click on a button, i should be able to pause a thread.
i have tried writing code in a function using <% ... %> tags, but they are executed automatically on page load. and when i click on the button, nothing happens.
Re: control thread using javascript button in jsp
If you want this seamless so that the brower doesnt refresh the page when you click the button you will have to create an AJAX call.
Using jQuery for instance this makes it all really easy. See Ajax – jQuery API for more information.
Once you make the ajax call you need to have a servlet or something receiving this call and then just take it from there to pause the running state of the thread in question.
// Json
Re: control thread using javascript button in jsp
i have not done programming using AJAX yet.
it seems to be able to solve the problem.
will give it a try.
thanks.
Re: control thread using javascript button in jsp
Quote:
Originally Posted by
Json
If you want this seamless so that the brower doesnt refresh the page when you click the button you will have to create an AJAX call.
Using jQuery for instance this makes it all really easy. See
Ajax – jQuery API for more information.
Once you make the ajax call you need to have a servlet or something receiving this call and then just take it from there to pause the running state of the thread in question.
// Json
thanks for the advice.
but as i went through the Ajax books, i saw that only text-data can be passed between a server and client using jsp.
how can i locate the thread in the server and then control it ?
please suggest some coding example..
Re: control thread using javascript button in jsp
Well I guess you start up the server and start each thread you want to control, you then save these threads in lets say a map so that you have a reference to them.
Whenever you then make an AJAX request to the server like so for instance.
Quote:
http://myserver.location.domain/stopthread.action?thread=<NAME_OR_ID>
The NAME_OR_ID will then be used on your server side to look up the thread from the map and set whatever status you need to paused or whatever :)
Hope that makes any sense.
// Json