Buongiorno a tutti. Ho bisogno di un aiuto. Ho il seguente codice in una jsp:
codice:<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form method="post" action="InsertDataUser?dati"> <table border='2' id='my_table' class='tabella' cellspacing='0' cellpadding='0'> <thead><tr><th>EMAIL </th><th>INDIRIZZO </th><th>NUMERO DI TELEFONO</th></tr></thead> <tbody> </tbody> </table><br/> <input type='button' value='Inserisci elementi' onClick="aggiungiRiga('my_table')"/> <input type=submit name="Insert" value='Approva i dati' onClick="createList()" > </form> </body> <script type='text/javascript'> function aggiungiRiga(id_table){ var table = document.getElementById(id_table); var tbody = table.getElementsByTagName('tbody')[0]; var colonne = table.getElementsByTagName('th').length; for(var i=0; i<colonne; i++){ var tr = document.createElement('tr'); var td = document.createElement('td'); var td1 = document.createElement('td'); var td2 = document.createElement('td'); var input = document.createElement("input"); var input1 = document.createElement("input"); var input2 = document.createElement("input"); input.type = "text";input.setAttribute("name","email"); input1.type = "text";input1.setAttribute("name","indirizzo"); input2.type = "text";input2.setAttribute("name","numero"); td.appendChild(input); td1.appendChild(input1); td2.appendChild(input2); tr.appendChild(td); tr.appendChild(td1); tr.appendChild(td2); } tbody.appendChild(tr); } </script> <script> function createList(){ var table = document.getElementById('my_table'); var dati = new Array(); //var amtLst =newArray(); for(var i=0; i<table.rows.length; i++){ var row = table.rows[i]; for(var j=0; j<row.cells.length; j++){ var cell = row.cells[0]; dati.push( cell.innerText ); } } return dati; } </script> </html>
Come potrei fare per recuperare tutti i valori immessi nella tabella ed eventualmente scorrerli per poterli poi immettere nel DB? Vorrei poter recuperare le singole colonne (o tutta la tabella) con la servlet (menzionata nell'action del form). Per quale motivo non recupero nulla? Potete darmi un consiglio se sto agendo bene quanto meno nella logica?