jsp - Radio button and its associated values in html table (corresponding row) to a servlet -


<html>     <head>         <title>report</title>     </head>      <body>     <form action=allrep method="get">           <h1>report</h1>         <%          string url = "jdbc:mysql://localhost:3306/fees";         string user = "root";         string passswd = "password";         connection connection = drivermanager.getconnection(url,user,passswd);         statement statement = connection.createstatement();         resultset resultset =          statement.executequery("select * fee1") ;          %>         <table border="1">             <tr>             <th>select</th>             <th>id</th>             <th>name</th>             <th>fee</th>             <th>course</th>             <th>occupation</th>             <th>balance</th>             <th>date</th>             </tr>            <%     while (resultset.next()) { %>            <tr>            <td><input type="radio" name="setval"></td>            <td> <%= resultset.getstring(5) %> </td>            <td contenteditable="true"> <%= resultset.getstring(1) %> </td>            <input type="hidden" value="<%= resultset.getstring(1) %>" name="fname">            <td contenteditable="true"> <%= resultset.getstring(2) %> </td>            <td contenteditable="true"> <%= resultset.getstring(3) %> </td>            <td contenteditable="true"> <%= resultset.getstring(4) %> </td>            <td contenteditable="true"> <%= resultset.getstring(6) %> </td>            <td contenteditable="true"> <%= resultset.getstring(7) %> </td>            </tr>        <%             }         %>        </table>  <br><br>         <input type="submit" value="update record">           </form>     </body> </html> 

here's servlet code:

import java.io.ioexception; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse;  /**  * servlet implementation class allrep  */ public class allrep extends httpservlet {     private static final long serialversionuid = 1l;      /**      * @see httpservlet#httpservlet()      */     public allrep() {         super();         // todo auto-generated constructor stub     }      /**      * @see httpservlet#doget(httpservletrequest request, httpservletresponse response)      */     protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {          string radio=request.getparameter("setval");          if(radio!=null)         {             string fname=request.getparameter("fname");             system.out.println("you've ticked");             system.out.println(fname);         }         // todo auto-generated method stub     }  } 

in here regardless of radio button fname prints value first row.

when press second radio button want value of particular row, i'm getting value of first row when system.out.printf used.

the idea behind radiobuttons provide different value each <input type="radio name="setval> element setting value attribute. browser puts value of selected radiobutton parameter of defined name.

so use radiobutton , remove hidden parameter:

<input type="radio" name="setval" value="<%= resultset.getstring(1) %>" /> 

then retrieve it:

string fname=request.getparameter("setval"); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -