Dear, please request your support to solve a problem. I'm working on an application and I need to see how to capture the data from an html table with records that comes from another table with records but I can not do it since both tables are in different forms and I do not know how to send the data from the second table .
First table. This table receives data from a mysqlk database through a servlet through sessions.
<form method="POST" action="">
<table class="table table-hover" border="1" id="tabla1">
<tbody>
<tr id="a1">
<th>Awb</th>
<th>Origen</th>
<th>Destino</th>
<th>Piezas</th>
<th>Kilos</th>
<th>Volumen</th>
<th>Id Vuelo</th>
<th>Tramo</th>
<th>Mover</th>
</tr>
<%
try
{
for(int i=0; i<guia.size(); i++)
{
out.println("<tr id='a2'>");
out.println("<td class='check'>"+guia.get(i).getNumeroGuia()+"</td>");
out.println("<td class='check'>"+guia.get(i).getOrigenGuia()+"</td>");
out.println("<td class='check'>"+guia.get(i).getDestinoGuia()+"</td>");
//out.println("<td>"+guia.get(i).getOrigenVueloReserva()+"</td>");
out.println("<td class='check'>"+guia.get(i).getPiezasGuia()+"</td>");
out.println("<td class='check'>"+guia.get(i).getKilosGuia()+"</td>");
out.println("<td class='check'>"+guia.get(i).getVolumenGuia()+"</td>");
out.println("<td class='check'>"+guia.get(i).getIdVueloGuia()+"</td>");
out.println("<td class='check'>"+guia.get(i).getIdTramoGuia()+"</td>");
out.println("<td class='check'><input type='checkbox' size=5 name='txt_idvuelo_guia' class='form-control' value='"+guia.get(i).getIdVueloGuia()+"'></td>");
}
}
catch(java.lang.NullPointerException ex)
{
out.println("</tr>");
}
%>
</tbody>
</table>
</form>
This table by means of a javascript function, transfers the columns with the data to another html table.
Here javascript code.
<script>
$(document).ready(function(){
$('input[type=checkbox]').click(function() {
if($(this).is(":checked"))
{
// el checkbox esta marcado
// movemos la columna a la tabla2
var tr=$(this).parents("tr").appendTo("#tabla2 tbody");
}else{
// el checkbox esta desmarcado
// movemos la columna a la tabla1
var tr=$(this).parents("tr").appendTo("#tabla1 tbody");
}
});
});
</script>
Here is the second table, it receives the columns with the data from the previous table.
<form method="POST" action="movimientosCargaMoverCargaServlet.do">
<!--<div class="table-responsive">-->
<table class="table table-hover col-sm-6" border="1" id="tabla2">
<tbody>
<tr>
<th>Awb</th>
<th>Origen</th>
<th>Destino</th>
<th>Piezas</th>
<th>Kilos</th>
<th>Volumen</th>
<th>Id Vuelo</th>
<th>Tramo</th>
<th>Acción</th>
</tr>
</tbody>
</table>
<input type="submit" class="btn btn-primary" value="Asignar">
<input type="resert" class="btn btn-primary" value="Limpiar">
</form>
The second table has a button called Assign, with this button I want to send some parameters to a servlet to execute, but like the columns that move to the second table, they move visually with javascript since the second one table has not defined the columns in code, when you press the button Assign gives me an error and indicates null values.
Here the servlet that should receive the data.
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
Vuelo vuelo1=new Vuelo();
Folio f=new Folio();
PrintWriter out = response.getWriter();
Connection con=ConexionMysqlCargomove_db.getInstance().getConnection();
GuiasDao gdao = new GuiasDao();
ArrayList<Guia> guia = new ArrayList<Guia>();
Guia g=new Guia();
vuelo1.setIdVuelo(Integer.parseInt(request.getParameter("txt_id_vuelo_disp")));
g.setNumeroGuia((request.getParameter("txt_guia")));
guia.add(g);
PreparedStatement ps=(PreparedStatement)gdao.moverCarga(vuelo1, g);
for(int i=0;i<g.getNumeroGuia().length();i++)
{
out.println(guia.get(i).getNumeroGuia());
try {
if(request.getParameter("txt_id_vuelo_disp").isEmpty()&& request.getParameter("txt_guia").isEmpty())
{
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<link rel='stylesheet href=bootstrap/css/bootstrap.min.css'>");
out.println("<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>");
out.println("<script src='https://code.jquery.com/jquery-1.12.4.min.js'></script>");
out.println("<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>");
out.println("<title>Servlet Mover carga</title>");
out.println("</head>");
out.println("<body>");
out.println("<form>");
out.println("<div class='form-row'>");
out.println("<p> Error </p>");
}
else
{
out.println("<p> Registro Actualizado con exito </p>");
out.println("<p> se ha asignado el vuelo :'"+vuelo1.getIdVuelo()+"'</p>");
out.println("<p> Las guias afectadas son:'"+guia.get(i).getNumeroGuia()+"'</p>");
}
out.println("</div>");
out.println("</form>");
}
catch(java.lang.NumberFormatException ex)
{
out.println("<h1>'"+ex.getMessage()+"'</h1>");
}
finally {
out.println("</body>");
out.println("</html>");
out.close();
}
}
}
the text fields " txt_id_file_rvvailable " and " txt_id_file_rvvailable " are from other tables that are in other forms.
here is the code of the GuiasDao class, which is the one with the sql statement that I want to execute.
public ResultSet moverCarga(Vuelo v1,Vuelo v2)
{
try {
Connection conn=ConexionMysqlCargomove_db.getInstance().getConnection();
//st=(Statement)conn.createStatement();
pst=(PreparedStatement)conn.createStatement();
String SQLUpdate="";
SQLUpdate="UPDATE tvas t\n" +
"INNER JOIN rvas r\n" +
"ON(t.rvas_cod_seq_rvas = r.cod_seq_rvas)\n" +
"SET t.vlos_seq_vlos = '"+v1.getIdVuelo()+"'\n" +
"WHERE t.vlos_seq_vlos = '"+v2.getIdVuelo()+"';";;
pst=conn.prepareStatement(SQLUpdate);
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(GuiasDao.class.getName()).log(Level.SEVERE, null, ex.getStackTrace());
}
return res;
}
here is an image of how the process is.
Please, any help is appreciated.