Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: control thread using javascript button in jsp

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default 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

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Re: control thread using javascript button in jsp

    Quote Originally Posted by Json View Post
    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..

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default 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.

    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

Similar Threads

  1. Control Browser Back Button
    By Ganezan in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: January 1st, 2010, 07:21 AM
  2. control Browser Back Button
    By Ganezan in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 30th, 2009, 06:49 AM
  3. process control
    By ttsdinesh in forum Java Native Interface
    Replies: 6
    Last Post: October 27th, 2009, 06:29 PM
  4. How can i put session in Javascript?
    By rajani in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: July 8th, 2009, 12:46 PM
  5. Replies: 3
    Last Post: May 18th, 2009, 03:45 AM

Tags for this Thread