Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/04/2017, 04:52
sentoki79
 
Fecha de Ingreso: octubre-2013
Mensajes: 79
Antigüedad: 10 años, 6 meses
Puntos: 1
Problemas con JSTL

Buenas a todos,


estoy desarrollando un backend y estoy teniendo problemas en la pagina principal que muestra todos los registros de la tabla.
Cuando modifico, borro ó inserto no se actualizan los cambios al redirigirse a esa pagina principal(en mi caso index.jsp).

Mi idea es en ese index.jsp que con JSTL llame a una servlet que es la que realiza el select a la BBDD.
Vereis que la he implementado con una clase FOTO para que cree un objeto donde vaya guardando las variables de cada fila de la consulta.
Voy a pegar el codigo del JSP y de la servlet. Del JSP no pego desde el principio ya que he desarrollado sessiones, cierre por inactividad y control de errores que pueden marear un poco para encontrar el error. Pego el codigo aislado donde esta el error entre JSTL y la servlet-

Muchas gracias por la ayuda:


codigo JSP:
<%@ page language="java" import="imagenes.*"%>
<%@page import="javax.servlet.http.HttpSession" %>

<html>
<head>


<link href="media/dataTables/demo_page.css" rel="stylesheet" type="text/css" />
<link href="media/dataTables/demo_table.css" rel="stylesheet" type="text/css" />

</head>

<body id="dt_example">
<div id="container">


<div id="demo_jui">
<form method="post" action="borrado.do" id="formBorrado" name="formBorrado">
<table id="Jtabla" class="display">
<thead>
<tr>
<th></th>
<th></th>
<th>Nombre</th>
<th>Descripcion</th>
<th>Longitud</th>
<th>Latitud</th>
<th>Fotografia</th>
<th>Posicion en el mapa</th>



</tr>
</thead>
<tbody>
<% for(Fotos c: MostrarTablaImagenes.GetFotos()){ %>
<tr>
<td> <a href="actualiza.do?nombre=<%=c.getNombre()%>&descr ipcion=<%=c.getDescripcion()%>&Id=<%=c.getId()%>" >Modificar</a></td>
<td> <input id="caja" value="<%=c.getId()%>" name="caja" type="checkbox" required="false"/></td>
<td><%=c.getNombre()%></td>
<td><%=c.getDescripcion()%></td>
<td><%=c.getLongitud()%></td>
<td><%=c.getLatitud()%></td>
<td><a href="<%=c.getPath()%><%=c.getNombreFoto()%>" >VER FOTO</a></td>
<td><a href="http://localhost:8080/oldViewsBackEnd/maps2.jsp?Id=<%=c.getId()%>" >PULSA PARA VISUALIZAR EN MAPA</td>

</tr>
<% } %>

</tbody>
<a href="http://localhost:8080/oldViewsBackEnd/prueba.html" >Nueva Foto</a>
<input id="borrar" value="Borrar" name="borrar" type="button" onclick="confirmacion()"/>
<a href="http://localhost:8080/oldViewsBackEnd/maps.jsp" >VER MAPA</a>
</table>
</form>
<a href="logOut.do" >Deslogarse</a>
</div>
</div>
</body>
</html>
<%
}
}

catch( Exception e){}%>








Codigo SERVELT:

package imagenes;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;



@WebServlet(name = "MostrarTablaImagenes", urlPatterns = {"/MostrarTablaImagenes"})
public class MostrarTablaImagenes extends HttpServlet {




/// <summary>
/// Singleton collection of companies
/// </summary>
private static List<Fotos> FotosData = null;

/// <summary>
/// Method that returns all companies used in this example
/// </summary>
/// <returns>List of companies</returns>
public static List<Fotos> GetFotos()
{
if (FotosData == null)
{
FotosData = new LinkedList<Fotos>();
try {
ResultSet rs = null;
String consultaSQL = "select * from imagenes2";
JDBC helper = new JDBC();
rs = helper.Select(consultaSQL);

while (rs.next()) {
int Id = rs.getInt("Id");
String nombre = rs.getString("Nombre");
String descripcion = rs.getString("Descripcion");
String path = rs.getString("Path");
String nombreFoto = rs.getString("NombreArchivo");
String longitud = rs.getString("Longitud");
String latitud = rs.getString("Latitud");


FotosData.add(new Fotos(Id,nombre, descripcion,path,nombreFoto,longitud,latitud ));

}
}
catch (SQLException ex) {
}
}
return FotosData;
}

}