Dear, I would like to know how I can take a record of an html table through a checkbox using pure jsp. The idea is to mark a record with a checkbox and press a button, you can take the selected record and send it to a servlet.
here is the html table that has data that comes from a mysql database.
<div class="content container-fluid col-lg-10">
<div class="left panel-default">
<div class="title panel-heading">Seleccionar guías a mover</div>
<div class="panel-body panel panel-primary">
<form method="POST" action="moverCarga2.do">
<table class="table table-hover" 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'><input type='text' name='txt_guia' class='form-control' value='"+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='check_guia' class='form-control' value='"+guia.get(i).getNumeroGuia()+"'></td>");
out.println("<td class='check'><input type='checkbox' size=5 name='check_guia' class='form-control' value='"+guia.get(i).getNumeroGuia()+"'></td>");
}
}
catch(java.lang.NullPointerException ex)
{
out.println("</tr>");
}
%>
</tbody>
</table>
</form>
</div>
</div>
</div>
here is the servlet that receives the data.
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
Vuelo vuelo1=new Vuelo();
vuelo1.setIdVuelo(Integer.parseInt(request.getParameter("txt_id_vuelo_disp")));
String [] numGuia=request.getParameterValues("check_guia");
for(int i=0;i<numGuia.length;i++)
{
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)+"'</p>");
out.println("<p> Las guias afectadas son las siguientes:'"+numGuia[i]+"'</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 problem is that the system shows me NullPointerException error