代码如下
“target =”imain“> Inventario
Fecha
<input type="text" id="fecha_web" name="fecha_web">
</p>
<p>recepcionista
<label for="rut_recepcionista"></label>
<label for="select"></label>
<label for="rut_coordinador"> coordinador</label>
<label for="cmb_cord"></label>
<select name="cmb_cord" id="cmb_cord">
<c:forEach var="fila_cord" items="${listaCoordinador}">
<option value="<c:out value="${fila_cord.run}" />" >
<c:out value="${fila_cord.nombres}" />
</option>
</c:forEach>
</select>
</p>
<table width="428" border="1">
<tr>
<th width="127" scope="col">Material</th>
<th width="168" scope="col">Cantidad</th>
<th width="111" scope="col">Cantidad previa</th>
</tr>
<c:forEach var="fila_m" items="${listaMat}" varStatus="status">
<tr>
<td><c:out value="${fila_m.nombre_material}" /></td>
<td><input type="text" name="total_actual" id="total_actual"
value="<c:out value="${fila_m.cant_material_total}"/>" /></td>
<td> <input name="cant_totalpub" type="text" id="cant_totalpub" value="<c:out value="${fila_m.cant_material_total}" />" disabled/>
<input name="cant_totalhid" type="text" id="cant_totalhid" value="<c:out value="${fila_m.cant_material_total}" />" hidden/>
<input name="mathid" id="mathid" type="text" size="1" value="<c:out value="${fila_m.cod_material}"/>" hidden></td>
</tr>
</c:forEach>
</table>
<p>
<label>guardar
<input type="submit" name="guardar" id="guardar" value="Submit" />
<br />
</label>
</p>
</form>
</body>
</html>
即.jsp和servlet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
Connection conexion = null;
try {
/* TODO output your page here. You may use following sample code. */
conexion = ds.getConnection();
InventarioDAO dao = new InventarioDAO();
dao.setCon(conexion);
Inventario inventario= new Inventario();
String fecha = request.getParameter("fecha_web");
int Rut_coordinador = Integer.parseInt(request.getParameter("rut_cord_web"));
int Cod_material = Integer.parseInt(request.getParameter("cod_material_web"));
int cant_actual = Integer.parseInt(request.getParameter("cant_actual_web"));
int cant_total = Integer.parseInt(request.getParameter("cant_total_web"));
inventario.setCant_material_actual(cant_actual);
inventario.setCant_material_total(cant_actual);
inventario.setCod_material(Cod_material);
inventario.setFecha(fecha);
inventario.setRut_coordinador(Rut_coordinador);
dao.guardarInventario(inventario);
//revisar bien donde tengo que enviarlo
request.getRequestDispatcher("/ListarHGServlet").forward(request, response);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conexion.close();
} catch (Exception noGestionar) {
}
}
}
问题是实际上有效,但它只是将实现的操作保存到列表中的第一个,同时其余部分被忽略,我想知道如何实现列表中每个项目的操作,我已经一直在寻找但有点我似乎找不到我需要的东西。
P.S:我不会说英语作为第一语言,所以对于由此造成的任何问题感到抱歉。答案 0 :(得分:0)
String fecha_web = request.getParameter("fecha_web");
//用于具有相同名称的多个表单元素。
String total_actuals[] = request.getParameterValues("total_actual");
String cant_totalpubs[] = request.getParameterValues("cant_totalpub");
String cant_totalhids[] = request.getParameterValues("cant_totalhid");
String mathids[] = request.getParameterValues("mathid");
if(mathids!=null)
{
for(int i=0;i<mathids.length;i++)
{
int total_actual = Integer.parseInt(total_actuals[i]);
int cant_totalpub = Integer.parseInt(cant_totalpubs[i]);
int mathid = Integer.parseInt(mathids[i]);
}
}