title: Getting the values from dynamically added rows and storing into database
body: <p>Here is my jsp code am adding the rows dynamically by using javascript with name particulars and amount how to get this dynamically added  rows values into the database and here am passing through beans creating the object and am fetching at the servlet side .  </p>
  
  <pre><code>&lt;form action="ClientBean.jsp" method="post"&gt;
   &lt;TD&gt;
    &lt;input type="text" name="particulars" style="width:600px;height: 20px;"&gt;
   &lt;/TD&gt; 
   &lt;TD&gt;
    &lt;input type="text" name="amount" style="width:150px;height:20px; "&gt;
   &lt;/TD&gt;
  &lt;/TR&gt;
  &lt;/table&gt;
  &lt;INPUT type="button" value="Add Row" onclick="addRow('tbl_comercial')" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the javascript code that will create the rows dynamically with the values   </p>
  
  <pre><code>function addRow(tbl_comercial){
    var table = document.getElementById(tbl_comercial);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "text";
    element1.name="particulars1[]";
    element1.size = 95;
    cell1.appendChild(element1);
    var cell2 = row.insertCell(1);
    var element2 = document.createElement("input");
    element2.type = "text";
    element2.name = "amount1[]";
    cell2.appendChild(element2);
  }
  </code></pre>
  
  <p>Here is the Servlet code </p>
  
  <pre><code>if (uri.contains("/Qutetioninsertion.do")) {
    System.out.println("inside client");
    ClientBean rb = (ClientBean) request.getAttribute("reg");
    Qoutetion model = new Qoutetion();
    String result=model.client(rb);
    if(result.contains("success")){
      rd = request.getRequestDispatcher("qutetiongenarationform.jsp");
      request.setAttribute("successmsg", result);
      rd.forward(request, response);  
    }
    else{
      rd = request.getRequestDispatcher("loginerror.jsp");
      request.setAttribute("errormsg",result);
      rd.forward(request, response);
    }
  }
  </code></pre>
  
  <p>Here is the java code </p>
  
  <pre><code>sql ="insert into commercial(particulars,amount) values(?,?)";
  ps2 = con.prepareStatement(sql);
  ps2.setString(1, rb.getParticulars());
  ps2.setInt(2,rb.getAmount());
  ps2.execute();
  con.commit();
  </code></pre>
  
  <p>Here is my bean code</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;jsp:useBean id="reg" class="com.uttara.reg.ClientBean" scope="request"&gt;
          &lt;jsp:setProperty name="reg" property="*"/&gt;
      &lt;/jsp:useBean&gt;
      &lt;jsp:forward page="Qutetioninsertion.do"/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>