Results 1 to 8 of 8
  1. #1
    sun
    sun is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default threads in jsp and servlets

    hello
    i am doing a program where i am transferring data between jsp and servlets.

    In one servlet(Add.java), i am creating threads and passing it to one showAll.jsp using ArrayList of threads.

    I want to control each thread, (pause and resume it) when a user clicks a button on the jsp page.
    I tried using the onClick event for the button, but it is getting executed when the page loads, whereas nothing happens when i click the button on the jsp page.
    please suggest me a way to achieve the functionality.


    following is my showAll.jsp code----------------------------------------------------


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <%@ page language="java" %>

    <%@ page import="data.user.UserBean" %>
    <%@ page import="java.util.*" %>
    <%@ page import="javax.servlet.http.Cookie" %>
    <%@ page import="javax.servlet.http.HttpServletRequest" %>

    <jsp:useBean id="db" scope="request" class="data.user.UserBean" />
    <% UserBean element =new UserBean(); %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>

    <jsp:useBean id="db1" scope="request" class="data.user.UserBean" />

    <center> <h1>Current Download Details</h1>
    </center>
    <%
    String user_id = (String) session.getAttribute("userid");
    ArrayList<Thread> tarr = (ArrayList<Thread>) session.getAttribute("tlist");
    if(tarr!=null)
    out.println("\n\n tlist received..");

    %>

    <form name="form1" method="post" action="AddNew">

    <table style="width: 100%" class="style1" border="1" align="center">
    <!-- MSTableType="layout" -->
    <tr>
    <td>file_Name</td>
    <td>Status</td>
    <td>button</td>
    <%

    Vector v = (Vector) request.getAttribute("myObject");

    if (v != null) {

    for (Iterator iter = v.iterator(); iter.hasNext();) {
    element = (UserBean) iter.next();
    out.println("<tr>");
    out.println("<td>" + element.getFile_name() + "</td>");
    out.println("<td>" + element.getStatus() + "</td>");
    out.println("<td> <input type='button' value='Pause/Resume' onClick='");

    if(tarr!=null)
    for (Iterator it3 = tarr.iterator();it3.hasNext();){

    Thread temp = (Thread) it3.next();
    if(temp.getName().equalsIgnoreCase(element.getFile _name()))
    temp.wait(30000);
    }
    out.println("'> </td>");

    }
    }
    %>
    </table>
    </form>
    </body>
    </html>

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    What do you think is supposed to happen?

  3. #3
    sun
    sun is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    What do you think is supposed to happen?
    on clicking the button, i should be able to pause and resume the individual threads.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I'm just checking you're not expecting that Java code you have after the onClick is actually going to run.

  5. #5
    sun
    sun is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    I'm just checking you're not expecting that Java code you have after the onClick is actually going to run.
    i didn't understand what you are trying to tell/ask !
    the code in the onClick event executes automatically when the page loads the first time, but it is not executing when i press the button.
    I want to say that the code should Work only for the onClick event, and not in any otherwise. how can i achieve this?

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Because that code executes on the server and not on the client.
    Look at the html that appears on the client and you'll see that it doesn't exist there at all in the onClick.

  7. #7
    sun
    sun is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    so how can i achieve my goal of controlling the threads using buttons on a jsp page ?
    is there another way??

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Without knowing what you're trying to actually achieve I can't easily say.

    But whatever it is, the threads will be on the server...and all your Java runs on the server...and any buttons pushed are in the browser. So all you can do is use the button to make a request to the server. How this would tie in with your thread stuff I really don't know.

Similar Threads

  1. servlets
    By priyacvr in forum Java Servlet
    Replies: 2
    Last Post: 09-28-2009, 07:43 AM
  2. Servlets
    By javahelp00 in forum New To Java
    Replies: 1
    Last Post: 02-28-2009, 06:28 PM
  3. servlets or jsp
    By krishnapal in forum Advanced Java
    Replies: 1
    Last Post: 12-13-2007, 02:31 PM
  4. Servlets and threads.
    By Marty in forum Threads and Synchronization
    Replies: 5
    Last Post: 08-10-2007, 12:20 AM
  5. Servlets
    By nagaroopanandha in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 02:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •