I am new to the forum and do not put things with code and others, but I will try to explain all things JSP code
<%@ page language="java" %>
<%@ page import = "IDP_web.Herramientas.ListaJefaturas"%>
<%@ page import = "IDP_web.Herramientas.Consultas"%>
<%@ page import = "java.util.LinkedList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://localhost:8080/ii/jefa.css">
</head>
<body>
<form action="/IDP_web/s">
<TABLE align="center">
<TR>
<tr>
<TH>Código de la Jefatura</TH>
<TH>Nombre de la Jefatura</TH>
<TH>Encargado de la jefatura</TH>
</TR>
<TR>
<tr>
<td>codigo</td>
<td>Nombre</td>
<td>Encargado</td>
</tr>
<%
LinkedList<ListaJefaturas> lista = Herramientas.Consultas.getJefaturas();
for (int i = 0; i < lista.size(); i++) {
out.println("<tr>");
out.println("<td>" + lista.get(i).getcodigo() + "</td>");
out.println("<td>" + lista.get(i).getNombre() + "</td>");
out.println("<td>" + lista.get(i).getEncargado() + "</td>");
out.println("</tr>");
}
%>
</table>
</form>
</body>
</html>
Code where I make the query to the database, Code is int, Name is varchar and Equal manager varchar
public static LinkedList<ListaJefaturas> getJefaturas() {
LinkedList<ListaJefaturas> lista = new LinkedList<ListaJefaturas>();
try {
Statement st = connect().createStatement();
ResultSet rs = st.executeQuery("select Codigo,Nombre,Encargado from Jefas");
while (rs.next()) {
ListaJefaturas LJ = new ListaJefaturas();
LJ.setCodigo(rs.getInt("Codigo"));
LJ.setNombre(rs.getString("nombre"));
LJ.setEncargado(rs.getString("Encargado"));
lista.add(LJ);
}
rs.close();
st.close();
connect().close();
} catch (Exception e) {
e.printStackTrace();
}
return lista;
}
Class with the get and set
public class ListaJefaturas {
private int Codigo;
private String nombre;
private String Encargado;
public int getCodigo() {
return Codigo;
}
public void setCodigo(int Codigo) {
this.Codigo = Codigo;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getEncargado() {
return Encargado;
}
public void setEncargado(String Encargado) {
this.Encargado = Encargado;
}
}