Commit 0ff36db1 by Rebecca Arzamendia

filtro de profesor

parent 22f3b1f0
......@@ -10,7 +10,7 @@
</list>
</option>
</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" />
</component>
</project>
\ No newline at end of file
......@@ -17,9 +17,9 @@ public class EditServlet extends HttpServlet {
int id = Integer.parseInt(request.getParameter("id"));
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");
rd.include(request, response);
}
......@@ -36,13 +36,13 @@ public class EditServlet extends HttpServlet {
Profesor profesor =new Profesor(nro_cedula, nombre, apellido, email);
profesor.setId(id);
int status=ProfesorDao.update(profesor);
// int status=ProfesorDao.update(profesor);
if(status>0){
response.sendRedirect("formulario_profesor.jsp");
}else{
System.out.println("Sorry! unable to update record");
}
// if(status>0){
// response.sendRedirect("formulario_profesor.jsp");
// }else{
// 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;
import com.roshka.proyectofinal.DataBase;
import com.roshka.proyectofinal.entity.Lenguaje;
import com.roshka.proyectofinal.entity.Profesor;
import java.sql.Connection;
......@@ -31,55 +30,54 @@ public class ProfesorDao {
return status;
}
public static List<Profesor> listar(){
public static List<Profesor> listarProfesor(){
ArrayList<Profesor> list = new ArrayList<>();
String sql = "select * from profesor";
try{
Connection con= DataBase.getConnection();
PreparedStatement ps=con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()){
Profesor profe = new Profesor();
profe.setId(rs.getInt("id"));
profe.setNombre(rs.getString("nombre"));
profe.setApellido(rs.getString("apellido"));
profe.setNro_cedula(rs.getInt("nro_cedula"));
profe.setCorreo(rs.getString("correo"));
list.add(profe);
Profesor profesorObject = new Profesor();
profesorObject.setNombre(rs.getString("nombre"));
profesorObject.setApellido(rs.getString("apellido"));
profesorObject.setNro_cedula(rs.getInt("nro_cedula"));
profesorObject.setCorreo(rs.getString("correo"));
list.add(profesorObject);
}
con.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return list;
}
public static int update(Profesor p){
int status=0;
public static List<Profesor> buscarPorNombre(String nombre, String apellido){
List<Profesor> profesores = new ArrayList<>();
Profesor profesorObject = new Profesor();
try{
Connection con= DataBase.getConnection();
PreparedStatement ps=con.prepareStatement(
"update profesor set nombre=?, apellido=?, correo=?, nro_cedula=? where id=?");
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());
PreparedStatement ps=con.prepareStatement("select a.id, a.nombre, a.apellido, a.nro_cedula, a.correo from profesor a " +
" where a.nombre ilike ? and a.apellido ilike ? ");
status=ps.executeUpdate();
con.close();
}catch(Exception ex){ex.printStackTrace();}
ps.setString(1, "%" + nombre + "%");
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){
int status=0;
try{
......@@ -93,25 +91,4 @@ public class ProfesorDao {
return status;
}
public static Profesor getProfesorById(int id){
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;
}
}
\ No newline at end of file
......@@ -11,8 +11,9 @@
</head>
<body>
<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" %>
......@@ -21,7 +22,7 @@
<div>
<%
ProfesorDao profeDao = new ProfesorDao();
List<Profesor> listProfe = profeDao.listar();
List<Profesor> listProfe = profeDao.listarProfesor();
Iterator<Profesor> iterProfe = listProfe.iterator();
Profesor profesor = null;
%>
......@@ -52,6 +53,14 @@
</button>
</form>
<br>
<form action="filtros-profesor">
<input name="nombreBuscar">
<input name="apellidoBuscar">
<button type="submit">
Filtrar
</button>
</form>
<br>
<table>
<thead>
......
......@@ -45,7 +45,7 @@
</form>
</th>
<th>
<form action="filtros-postulante" method="post">
<form action="filtros-posjtulante" method="post">
<input type="hidden" name="nombre" value="aceptado">
<button type="submit">Aceptado</button>
</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