how to store html table data to mysql using jsp

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2249 Views - Last Post: 02 July 2015 - 03:13 AM

#1 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

how to store html table data to mysql using jsp

Posted 24 June 2015 - 02:02 AM

I wanna store html table data to the mysql database using jsp or servlet.

This is my jsp code
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="style.css">        
        <script>
    	
    	function addRow() {          
    	    var suplrName = document.getElementById("sprln");
    	    /* var invcdate = document.getElementById("invdId"); */
    	    var prdtype = document.getElementById("prdctype");
    	    var cattype = document.getElementById("catgtype");
    	    var grwt = document.getElementById("gw");
    	    var tare = document.getElementById("tr");
    	    var netwt = document.getElementById("nt");
    	    var soot = document.getElementById("st");
    	    var Fnetwt = document.getElementById("tnt");
    	    var rate = document.getElementById("rt");
    	    var Tot = document.getElementById("amt");
    	    
    	    var table = document.getElementById("myTableData");
    	 
    	    var rowCount = table.rows.length;
    	    var row = table.insertRow(rowCount);
    	 
    	    row.insertCell(0).innerHTML= rowCount+0;
    	    row.insertCell(1).innerHTML= suplrName.value;
    	    /* row.insertCell(2).innerHTML= invcdate.value; */
    	    row.insertCell(2).innerHTML= prdtype.value;
    	    row.insertCell(3).innerHTML= cattype.value;
    	    row.insertCell(4).innerHTML= grwt.value;
    	    row.insertCell(5).innerHTML= tare.value;
    	    row.insertCell(6).innerHTML= netwt.value;
    	    row.insertCell(7).innerHTML= soot.value;
    	    row.insertCell(8).innerHTML= Fnetwt.value;
    	    row.insertCell(9).innerHTML= rate.value;
    	    row.insertCell(10).innerHTML= Tot.value;   
    	    row.insertCell(11).innerHTML= '<input type="button" value = "Delete" onclick="Javacsript:deleteRow(this)">';
    	 
    	}
    	function load() {
    	    
    	    console.log("Page load finished");
    	 
    	}
    	function deleteRow(obj) {
    	      
    	    var index = obj.parentNode.parentNode.rowIndex;
    	    var table = document.getElementById("myTableData");
    	    table.deleteRow(index);
    	    
    	}    	
    	</script>
    </head>
    <body onload="load()">
      
                <div class="content" >                    
                        <table cellpadding="5" cellspacing="5">
                            <tr>
                                <td>Supplier Name:</td>
                                <td><input type="text" name="invcdate" id="sprln" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                
                                <!-- <td> Invoice Date:</td>
                                <td><input type="text" name="invcdate" id="invdId" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>   -->                              
                            </tr>
                            <tr>
                            	<td>Product Type:</td>
                                <td><input type="text" name="invcdate" id="prdctype" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>                              
                                <td>Category Type:</td>
                                <td> <input type="text" name="invcdate" id="catgtype" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
                                 
                                 
                            </tr>
                            <tr>                                
                                <td>Gross Weight:</td>
                           <td><input type="text" name="gweight" id="gw" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           <td> TARE: </td>
                           <td><input type="text" name="tare" id="tr" onkeyup="netrs()" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                 
                            </tr>
                            <tr>                                
                                  <td> Net Weight:</td>
                           <td><input type="text" name="netwt" id="nt" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                  <td> Soot:</td>
                           <td><input type="text" name="soot" id="st" onkeyup="tnetrs()" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>                         
                                  </tr>                
                       
                   		<tr>
                   		<td> Total Net Weight:</td>
                           <td><input type="text" name="totnetwt" id="tnt" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                  <td> Rate:</td>
                           <td><input type="text" name="rate" id="rt" onkeyup="tAmnt()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           </tr>                       
                       <tr>
                           <td> Amount:</td>
                           <td><input type="text" name="amnt" id="amt" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           
                              
                        </tr>                   		
                        <tr>
                        <td> &nbsp;&nbsp;  </td>
                        <td><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Submit" onclick="Javascript:addRow()"></td>
                           
                           <td><br><input type="button" name="cancel" value="Cancel"></td>                           
                           <td>&nbsp;&nbsp;</td>
                        </tr>
                   </table>
                   
                   <br>
                       
               
            </div>           
            
                       <div class="results">
                       
            	<table id="myTableData" border="1">
                			<tr>
                				<th>S.No </th>
                				<th>SupName </th>
                				<th>PrdName </th>
                				<th>CateName </th>
                				<th>GrossWt</th>
                				<th>Tare</th>
                				<th>NetWt</th>
                				<th>soot</th>
                				<th>TotNetWt</th>
                				<th>Rate</th>
                				<th>Amount</th>
                				<th>Delete</th>        				
                			</tr>                			
                				
                				
                			
                		</table>
                	<input type="submit" name="subt" value="Submit" onclick="Javascript:getrowc()">
                	<!-- </form> -->
                	<%
                	
                	%>
            </div>  
           
              
        
       
    </body>
</html>




An body suggest me .

Is This A Good Question/Topic? 0
  • +

Replies To: how to store html table data to mysql using jsp

#2 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 24 June 2015 - 05:14 AM

I'm reading on a phone, so code is hard to follow.

Obviously, you need to send data to the server. Do you know about relevant HTTP methods for doing so (e.g. POST)? Then, do you know how to handle those in a servlet? If not, I'd suggest doing some reading on those things, attempting something and showing us where you're stuck.

Sent from my LG-D802 using Tapatalk
Was This Post Helpful? 0
  • +
  • -

#3 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

Re: how to store html table data to mysql using jsp

Posted 24 June 2015 - 10:41 PM

I have tried that post method.

With that post method we can send <input type = text> value but,

how to send the html table data which is dynamically created .
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 25 June 2015 - 12:44 AM

What do you mean? How are the data dynamically generated? Do they come from a user or what?
Was This Post Helpful? 0
  • +
  • -

#5 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

Re: how to store html table data to mysql using jsp

Posted 25 June 2015 - 12:49 AM

yes it is from end user purchase list in trasaction
Was This Post Helpful? 0
  • +
  • -

#6 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 25 June 2015 - 12:55 AM

So, you have a form in which the user enters the data? What's wrong with submitting it in a POST request then?
Was This Post Helpful? 0
  • +
  • -

#7 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

Re: how to store html table data to mysql using jsp

Posted 25 June 2015 - 01:26 AM

My problem is how to can we transfer the table data

View Postdevarapalli, on 25 June 2015 - 01:54 PM, said:

My problem is how to can we transfer the table data


to persistance jsp and how to access that table data.
Was This Post Helpful? 0
  • +
  • -

#8 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 25 June 2015 - 01:36 AM

JSPs are the view component - they're used to generate the HTML that the client receives. You therefore don't submit data to them from the client.

Again, you need to submit a POST request containing the data from the user. You can of course submit values for multiple fields in one request. The servlet will then extract the data from the request, so you can do what you need to with it.
Was This Post Helpful? 0
  • +
  • -

#9 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 01 July 2015 - 12:15 AM

Have you made progress with this?
Was This Post Helpful? 0
  • +
  • -

#10 kathy025  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 175
  • Joined: 19-December 14

Re: how to store html table data to mysql using jsp

Posted 02 July 2015 - 01:04 AM

View Postdevarapalli, on 25 June 2015 - 04:26 PM, said:

My problem is how to can we transfer the table data

View Postdevarapalli, on 25 June 2015 - 01:54 PM, said:

My problem is how to can we transfer the table data


to persistance jsp and how to access that table data.

Are you familiar with forms?

You can put your table inside a form and submit all inputs (e.g. textfield, textarea, radio buttons, dropdowns, etc.) inside that form to a Servlet's doPost().
Was This Post Helpful? 0
  • +
  • -

#11 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

Re: how to store html table data to mysql using jsp

Posted 02 July 2015 - 01:33 AM

View Postkathy025, on 02 July 2015 - 01:34 PM, said:

View Postdevarapalli, on 25 June 2015 - 04:26 PM, said:

My problem is how to can we transfer the table data

View Postdevarapalli, on 25 June 2015 - 01:54 PM, said:

My problem is how to can we transfer the table data


to persistance jsp and how to access that table data.

Are you familiar with forms?

You can put your table inside a form and submit all inputs (e.g. textfield, textarea, radio buttons, dropdowns, etc.) inside that form to a Servlet's doPost().



i need to store table cell values not table feild values
Was This Post Helpful? 0
  • +
  • -

#12 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 02 July 2015 - 02:15 AM

I'm confused. What exactly do you mean?
Was This Post Helpful? 0
  • +
  • -

#13 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

Re: how to store html table data to mysql using jsp

Posted 02 July 2015 - 02:30 AM

View Postndc85430, on 02 July 2015 - 02:45 PM, said:

I'm confused. What exactly do you mean?



i want to Store the sale values.
Like,
Customer 1 : buy
S.no Product Qnty UnitCost Total

1. pro1 2 20 40
2. pro2 5 15 75

i want to store the entire table sale values.
Was This Post Helpful? 0
  • +
  • -

#14 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,479
  • Joined: 13-June 14

Re: how to store html table data to mysql using jsp

Posted 02 July 2015 - 02:49 AM

So again, why aren't these in a form whose data you submit to the server in a POST request?
Was This Post Helpful? 0
  • +
  • -

#15 devarapalli  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 28-October 13

Re: how to store html table data to mysql using jsp

Posted 02 July 2015 - 02:52 AM

View Postndc85430, on 02 July 2015 - 03:19 PM, said:

So again, why aren't these in a form whose data you submit to the server in a POST request?


how? can we access data by table id in servlet.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2