Commit 0ff36db1 by Rebecca Arzamendia

filtro de profesor

parent 22f3b1f0
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -17,9 +17,9 @@ public class EditServlet extends HttpServlet { ...@@ -17,9 +17,9 @@ public class EditServlet extends HttpServlet {
int id = Integer.parseInt(request.getParameter("id")); int id = Integer.parseInt(request.getParameter("id"));
ProfesorDao profesorDao = new ProfesorDao(); ProfesorDao profesorDao = new ProfesorDao();
Profesor profesor = profesorDao.getProfesorById(id); // Profesor profesor = profesorDao.getProfesorById(id);
request.setAttribute("Profesor", profesor); // request.setAttribute("Profesor", profesor);
RequestDispatcher rd = request.getRequestDispatcher("formulario_profesor.jsp"); RequestDispatcher rd = request.getRequestDispatcher("formulario_profesor.jsp");
rd.include(request, response); rd.include(request, response);
} }
...@@ -36,13 +36,13 @@ public class EditServlet extends HttpServlet { ...@@ -36,13 +36,13 @@ public class EditServlet extends HttpServlet {
Profesor profesor =new Profesor(nro_cedula, nombre, apellido, email); Profesor profesor =new Profesor(nro_cedula, nombre, apellido, email);
profesor.setId(id); profesor.setId(id);
int status=ProfesorDao.update(profesor); // int status=ProfesorDao.update(profesor);
if(status>0){ // if(status>0){
response.sendRedirect("formulario_profesor.jsp"); // response.sendRedirect("formulario_profesor.jsp");
}else{ // }else{
System.out.println("Sorry! unable to update record"); // System.out.println("Sorry! unable to update record");
} // }
} }
} }
package com.roshka.proyectofinal.profesor;
import com.roshka.proyectofinal.entity.Profesor;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import static com.roshka.proyectofinal.profesor.ProfesorDao.buscarPorNombre;
import static com.roshka.proyectofinal.profesor.ProfesorDao.listarProfesor;
@WebServlet("/filtros-profesor")
public class Filtros extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<Profesor> profesores = listarProfesor();
String nombre = req.getParameter("nombreBuscar");
String apellido = req.getParameter("apellidoBuscar");
System.out.println(nombre);
System.out.println(apellido);
if(nombre!=null || apellido!=null){
profesores = buscarPorNombre(nombre, apellido);
}
req.getServletContext().setAttribute("profesores", profesores);
RequestDispatcher reqDisp= req.getRequestDispatcher("profesor-consulta.jsp");
reqDisp.forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<Profesor > nombre = listarProfesor();
List<Profesor > apellido = listarProfesor();
req.getServletContext().setAttribute("nombre", nombre);
req.getServletContext().setAttribute("apellido", apellido);
RequestDispatcher reqDisp= req.getRequestDispatcher("profesor-consulta.jsp");
reqDisp.forward(req,resp);
}
}
package com.roshka.proyectofinal.profesor; package com.roshka.proyectofinal.profesor;
import com.roshka.proyectofinal.DataBase; import com.roshka.proyectofinal.DataBase;
import com.roshka.proyectofinal.entity.Lenguaje;
import com.roshka.proyectofinal.entity.Profesor; import com.roshka.proyectofinal.entity.Profesor;
import java.sql.Connection; import java.sql.Connection;
...@@ -31,55 +30,54 @@ public class ProfesorDao { ...@@ -31,55 +30,54 @@ public class ProfesorDao {
return status; return status;
} }
public static List<Profesor> listarProfesor(){
public static List<Profesor> listar(){
ArrayList<Profesor> list = new ArrayList<>(); ArrayList<Profesor> list = new ArrayList<>();
String sql = "select * from profesor"; String sql = "select * from profesor";
try{ try{
Connection con= DataBase.getConnection(); Connection con= DataBase.getConnection();
PreparedStatement ps=con.prepareStatement(sql); PreparedStatement ps=con.prepareStatement(sql);
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
while(rs.next()){ while(rs.next()){
Profesor profe = new Profesor(); Profesor profesorObject = new Profesor();
profe.setId(rs.getInt("id")); profesorObject.setNombre(rs.getString("nombre"));
profe.setNombre(rs.getString("nombre")); profesorObject.setApellido(rs.getString("apellido"));
profe.setApellido(rs.getString("apellido")); profesorObject.setNro_cedula(rs.getInt("nro_cedula"));
profe.setNro_cedula(rs.getInt("nro_cedula")); profesorObject.setCorreo(rs.getString("correo"));
profe.setCorreo(rs.getString("correo")); list.add(profesorObject);
list.add(profe);
} }
con.close(); con.close();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return list; return list;
} }
public static List<Profesor> buscarPorNombre(String nombre, String apellido){
public static int update(Profesor p){ List<Profesor> profesores = new ArrayList<>();
int status=0; Profesor profesorObject = new Profesor();
try{ try{
Connection con= DataBase.getConnection(); Connection con= DataBase.getConnection();
PreparedStatement ps=con.prepareStatement( PreparedStatement ps=con.prepareStatement("select a.id, a.nombre, a.apellido, a.nro_cedula, a.correo from profesor a " +
"update profesor set nombre=?, apellido=?, correo=?, nro_cedula=? where id=?"); " where a.nombre ilike ? and a.apellido ilike ? ");
ps.setString(1,p.getNombre());
ps.setString(2,p.getApellido());
ps.setString(3,p.getCorreo());
ps.setInt(4,p.getNro_cedula());
ps.setInt(5,p.getId());
status=ps.executeUpdate();
con.close(); ps.setString(1, "%" + nombre + "%");
}catch(Exception ex){ex.printStackTrace();} ps.setString(2, "%" + apellido + "%");
System.out.println(nombre);
ResultSet rs = ps.executeQuery();
while(rs.next()){
return status; profesorObject.setNombre(rs.getString("nombre"));
profesorObject.setApellido(rs.getString("apellido"));
profesorObject.setNro_cedula(rs.getInt("nro_cedula"));
profesorObject.setCorreo(rs.getString("correo"));
profesores.add(profesorObject);
}
con.close();
}catch(Exception ex){
ex.printStackTrace();
}
return profesores;
} }
public static int delete(int id){ public static int delete(int id){
int status=0; int status=0;
try{ try{
...@@ -93,25 +91,4 @@ public class ProfesorDao { ...@@ -93,25 +91,4 @@ public class ProfesorDao {
return status; return status;
} }
}
public static Profesor getProfesorById(int id){ \ No newline at end of file
Profesor p=new Profesor();
try{
Connection con=DataBase.getConnection();
PreparedStatement ps=con.prepareStatement("select * from profesor where id=?");
ps.setInt(1,id);
ResultSet rs=ps.executeQuery();
if(rs.next()){
p.setId(rs.getInt("id"));
p.setNombre(rs.getString("nombre"));
p.setApellido(rs.getString("apellido"));
p.setNro_cedula(rs.getInt("nro_cedula"));
p.setCorreo(rs.getString("correo"));
}
con.close();
}catch(Exception ex){ex.printStackTrace();}
return p;
}
}
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
</head> </head>
<body> <body>
<div> <div>
<h1> CREAR PROFESOR </h1> <h1> CREAR PROFESOR Y FILTRAR </h1>
<%@ page import="com.roshka.proyectofinal.entity.Profesor, com.roshka.proyectofinal.profesor.ProfesorDao, java.util.List,java.util.Iterator" %> <%@ page import="com.roshka.proyectofinal.entity.Profesor, com.roshka.proyectofinal.profesor.ProfesorDao, java.util.List,java.util.Iterator" %>
...@@ -21,7 +22,7 @@ ...@@ -21,7 +22,7 @@
<div> <div>
<% <%
ProfesorDao profeDao = new ProfesorDao(); ProfesorDao profeDao = new ProfesorDao();
List<Profesor> listProfe = profeDao.listar(); List<Profesor> listProfe = profeDao.listarProfesor();
Iterator<Profesor> iterProfe = listProfe.iterator(); Iterator<Profesor> iterProfe = listProfe.iterator();
Profesor profesor = null; Profesor profesor = null;
%> %>
...@@ -51,6 +52,14 @@ ...@@ -51,6 +52,14 @@
Crear Profesor Crear Profesor
</button> </button>
</form> </form>
<br>
<form action="filtros-profesor">
<input name="nombreBuscar">
<input name="apellidoBuscar">
<button type="submit">
Filtrar
</button>
</form>
<br> <br>
<table> <table>
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
</form> </form>
</th> </th>
<th> <th>
<form action="filtros-postulante" method="post"> <form action="filtros-posjtulante" method="post">
<input type="hidden" name="nombre" value="aceptado"> <input type="hidden" name="nombre" value="aceptado">
<button type="submit">Aceptado</button> <button type="submit">Aceptado</button>
</form> </form>
......
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!-- el icono para la pagina -->
<link rel="shortcut icon" href="imagenes/roshkaicon.ico" sizes="any" />
<!-- coneccion con el de css -->
<link rel="stylesheet" href="postulante.css">
<title> Profesor MANAGE </title>
</head>
<body>
<div>
<h1>LISTA PROFESORES</h1>
<form action="filtros-profesor" >
<input type="search" name="nombreBuscar"
placeholder="Buscar por nombre">
<input type="search" name="apellidoBuscar"
placeholder="Buscar por apellido">
<button type="submit">Buscar</button>
</form>
<table>
<tr>
<th>#</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Numero de Cedula</th>
<th>Correo</th>
<th>Editar</th>
<th>Eliminar</th>
</tr>
<tbody>
<c:forEach var="profesor" items="${profesores}" varStatus="myIndex">
<tr>
<td> ${myIndex.index + 1}-</td>
<td> ${profesor.nombre}</td>
<td> ${profesor.apellido}</td>
<td> ${profesor.nro_cedula}</td>
<td> ${profesor.correo}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment