JSP (Java Server Page) - Ayuda con editar y eliminar registros en jso

 
Vista:

Ayuda con editar y eliminar registros en jso

Publicado por Pedro (3 intervenciones) el 30/04/2009 17:18:17
Tengo una tabla dinámica con base de datos generada en dreamweaver.
A la tabla le agregué dos columnas para agregar los campos editar y eliminar. En esas dos columnas tuve que capturar la id para enviar a las páginas de editar y eliminar.(editar2.jsp?IdAlumno=00001).
Pero solo se ejecuta la página cuando pongo solo una columna, editar o eliminar. Cuando pongo el código para los dos editar y eliminar sale error.El error dice:
org.apache.jasper.JasperException: Exception in JSP: /sitio_jsp/mant.jsp:44

41: <td><%=(((Recordset1_data = Recordset1.getObject("idDistrito"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
42: <td><%=(((Recordset1_data = Recordset1.getObject("idSexo"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
43: <td><A href="actualizar2.jsp?idAlumno=<%=(((Recordset1_data = Recordset1.getObject("idAlumno"))==null || Recordset1.wasNull())?"":Recordset1_data)%>">Actualizar</A></td>
44: <td><A href="eliminar2.jsp?idAlumno=<%=(((Recordset1_data = Recordset1.getObject("idAlumno"))==null || Recordset1.wasNull())?"":Recordset1_data)%>">Eliminar</A></td>
45: </tr>
46:
47: <%

Creo que el error sale cuando se usa el getObjet() 2 veces para capturar IdAlumno en la columna editar y eliminar. Probé con getInt y getString pero no se soluciona el error.

Ahí pongo el código para ver si me pueden ayudar.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="Connections/cn.jsp" %>
<%
Driver DriverRecordset1 = (Driver)Class.forName(MM_cn_DRIVER).newInstance();
Connection ConnRecordset1 = DriverManager.getConnection(MM_cn_STRING,MM_cn_USERNAME,MM_cn_PASSWORD);
PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM prueba.alumno ORDER BY idAlumno ASC");
ResultSet Recordset1 = StatementRecordset1.executeQuery();
boolean Recordset1_isEmpty = !Recordset1.next();
boolean Recordset1_hasData = !Recordset1_isEmpty;
Object Recordset1_data;
int Recordset1_numRows = 0;
%>
<%
int Repeat1__numRows = -1;
int Repeat1__index = 0;
Recordset1_numRows += Repeat1__numRows;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<table border="1">
<tr>
<td>idAlumno</td>
<td>paterno</td>
<td>materno</td>
<td>nombre</td>
<td>idDistrito</td>
<td>idSexo</td>
</tr>
<% while ((Recordset1_hasData)&&(Repeat1__numRows-- != 0)) { %>
<tr>
<td><%=(((Recordset1_data = Recordset1.getObject("idAlumno"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
<td><%=(((Recordset1_data = Recordset1.getObject("paterno"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
<td><%=(((Recordset1_data = Recordset1.getObject("materno"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
<td><%=(((Recordset1_data = Recordset1.getObject("nombre"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
<td><%=(((Recordset1_data = Recordset1.getObject("idDistrito"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
<td><%=(((Recordset1_data = Recordset1.getObject("idSexo"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
<td><A href="actualizar2.jsp?idAlumno=<%=(((Recordset1_data = Recordset1.getObject("idAlumno"))==null || Recordset1.wasNull())?"":Recordset1_data)%>">Actualizar</A></td>
<td><A href="eliminar2.jsp?idAlumno=<%=(((Recordset1_data = Recordset1.getObject("idAlumno"))==null || Recordset1.wasNull())?"":Recordset1_data)%>">Eliminar</A></td>
</tr>

<%
Repeat1__index++;
Recordset1_hasData = Recordset1.next();
}
%>
</table>
</body>
</html>
<%
Recordset1.close();
StatementRecordset1.close();
ConnRecordset1.close();
%>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ayuda con editar y eliminar registros en jso

Publicado por lunatriste (3 intervenciones) el 01/05/2009 02:16:02
Hola...mira yo tengo este codigo es similar a lo que deseas hacer, debes generar tu juego de registors y repetir la region, de dicho registro te dejo este espero te sirva...
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="../../Connections/con2.jsp" %>
<%
Driver Driverrs_servicios = (Driver)Class.forName(MM_con2_DRIVER).newInstance();
Connection Connrs_servicios = DriverManager.getConnection(MM_con2_STRING,MM_con2_USERNAME,MM_con2_PASSWORD);
PreparedStatement Statementrs_servicios = Connrs_servicios.prepareStatement("SELECT * FROM siscor.servicio ORDER BY clave_servicio ASC");
ResultSet rs_servicios = Statementrs_servicios.executeQuery();
boolean rs_servicios_isEmpty = !rs_servicios.next();
boolean rs_servicios_hasData = !rs_servicios_isEmpty;
Object rs_servicios_data;
int rs_servicios_numRows = 0;
%>
<%
int Repeat1__numRows = -1;
int Repeat1__index = 0;
rs_servicios_numRows += Repeat1__numRows;
%>
<%
// *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

int rs_servicios_first = 1;
int rs_servicios_last = 1;
int rs_servicios_total = -1;

if (rs_servicios_isEmpty) {
rs_servicios_total = rs_servicios_first = rs_servicios_last = 0;
}

//set the number of rows displayed on this page
if (rs_servicios_numRows == 0) {
rs_servicios_numRows = 1;
}
%>
<%
// *** Recordset Stats: if we don't know the record count, manually count them

if (rs_servicios_total == -1) {

// count the total records by iterating through the recordset
for (rs_servicios_total = 1; rs_servicios.next(); rs_servicios_total++);

// reset the cursor to the beginning
rs_servicios.close();
rs_servicios = Statementrs_servicios.executeQuery();
rs_servicios_hasData = rs_servicios.next();

// set the number of rows displayed on this page
if (rs_servicios_numRows < 0 || rs_servicios_numRows > rs_servicios_total) {
rs_servicios_numRows = rs_servicios_total;
}

// set the first and last displayed record
rs_servicios_first = Math.min(rs_servicios_first, rs_servicios_total);
rs_servicios_last = Math.min(rs_servicios_first + rs_servicios_numRows - 1, rs_servicios_total);
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Catálogo de Servicios</title>
</head>

<body>
<table width="700" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" align="center"><h1>Catálogo de Servicios </h1></td>
</tr>
<tr>
<td width="300"> 
</th> </td>
<td width="223"> </td>
<td width="44"> </td>
<td width="53"><a href="alta_servicio.jsp">Nuevo</a></td>
<td width="68"><a href="../../reportes/reporte_servicios.jsp" target="_blank">Imprimir</a></td>
</tr>
<tr>
<td>Id
</th> </td>
<td>Servicios</td>
<td colspan="3" align="center">acción</td>
</tr>
<% while ((rs_servicios_hasData)&&(Repeat1__numRows-- != 0)) { %>
<tr>
<td> <%=(((rs_servicios_data = rs_servicios.getObject("CLAVE_SERVICIO"))==null || rs_servicios.wasNull())?"":rs_servicios_data)%> </th> </td>
<td><%=(((rs_servicios_data = rs_servicios.getObject("TIPO_SERVICIO"))==null || rs_servicios.wasNull())?"":rs_servicios_data)%></td>
<td><a href="mostrar_servicios.jsp?id=<%=(((rs_servicios_data = rs_servicios.getObject("CLAVE_SERVICIO"))==null || rs_servicios.wasNull())?"":rs_servicios_data)%>">Ver</a></td>
<td><a href="modificar_servicio.jsp?id=<%=(((rs_servicios_data = rs_servicios.getObject("CLAVE_SERVICIO"))==null || rs_servicios.wasNull())?"":rs_servicios_data)%>">Editar</a></td>
<td><a href="baja_servicio.jsp?id=<%=(((rs_servicios_data = rs_servicios.getObject("CLAVE_SERVICIO"))==null || rs_servicios.wasNull())?"":rs_servicios_data)%>">Borrar</a></td>
</tr>
<%
Repeat1__index++;
rs_servicios_hasData = rs_servicios.next();
}
%>
<tr>
<td colspan="5"> 
</th>
Hay <%=(rs_servicios_total)%> registros en la base </td>
</tr>
</table>
<p><a href="../menu.jsp">*Menú</a></p>
</body>
</html>
<%
rs_servicios.close();
Statementrs_servicios.close();
Connrs_servicios.close();
%>

esto de ayuda a eliminar. modificar, crear un nuevo registro, e imprimir solo ke aki tenemos una falla aun no sabemos como imprimir solo un registro...
Salu2
espero te ayude...suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ayuda con editar y eliminar registros en jso

Publicado por Pedro (3 intervenciones) el 01/05/2009 19:37:47
Gracias por tu respuesta. No puedo ver en el código como repetir la región de registros.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar