From 35b9138fe7c94b7e34aa30be468ecefe3d469663 Mon Sep 17 00:00:00 2001 From: Emanuel Date: Thu, 12 May 2022 07:30:22 -0400 Subject: [PATCH] login parcial --- .idea/encodings.xml | 1 + src/main/java/com/roshka/proyectofinal/entity/LoginBean.java | 22 ++++++++++++++++++++++ src/main/java/com/roshka/proyectofinal/login/LoginDao.java | 33 +++++++++++++++++++++++++++++++++ src/main/java/com/roshka/proyectofinal/login/LoginServlet.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/webapp/login.jsp | 2 +- 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/roshka/proyectofinal/entity/LoginBean.java create mode 100644 src/main/java/com/roshka/proyectofinal/login/LoginDao.java create mode 100644 src/main/java/com/roshka/proyectofinal/login/LoginServlet.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 63e9001..aa00ffa 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/src/main/java/com/roshka/proyectofinal/entity/LoginBean.java b/src/main/java/com/roshka/proyectofinal/entity/LoginBean.java new file mode 100644 index 0000000..9b2ad7e --- /dev/null +++ b/src/main/java/com/roshka/proyectofinal/entity/LoginBean.java @@ -0,0 +1,22 @@ +package com.roshka.proyectofinal.entity; + +public class LoginBean { + private String username; + private String password; + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/main/java/com/roshka/proyectofinal/login/LoginDao.java b/src/main/java/com/roshka/proyectofinal/login/LoginDao.java new file mode 100644 index 0000000..8ab20f8 --- /dev/null +++ b/src/main/java/com/roshka/proyectofinal/login/LoginDao.java @@ -0,0 +1,33 @@ +package com.roshka.proyectofinal.login; + +import com.roshka.proyectofinal.DataBase; +import com.roshka.proyectofinal.entity.Lenguaje; +import com.roshka.proyectofinal.entity.LoginBean; + +import java.sql.Connection; +import java.sql.PreparedStatement; + +public class LoginDao { + + public boolean validate (LoginBean loginBean) { + int status = 0; + try { + Connection con = DataBase.getConnection(); + + PreparedStatement ps=con.prepareStatement( + "select * from usuarios where username=? and password = ?"); + ps.setString(1,loginBean.getUsername()); + ps.setString(2, loginBean.getPassword()); + status=ps.executeUpdate(); + + con.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + + if (status > 0) return true ; + else return false ; + + } + +} diff --git a/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java b/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java new file mode 100644 index 0000000..c251007 --- /dev/null +++ b/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java @@ -0,0 +1,61 @@ +package com.roshka.proyectofinal.login; + + +import java.io.IOException; +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 com.roshka.proyectofinal.entity.LoginBean; + +/** + * Servlet implementation class LoginServlet + */ +@WebServlet("/login") +public class LoginServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public LoginServlet() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + response.getWriter().append("Served at: ").append(request.getContextPath()); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + LoginDao loginDao = new LoginDao(); + + String username = request.getParameter("username"); + String password = request.getParameter("password"); + LoginBean loginBean = new LoginBean(); + loginBean.setUsername(username); + loginBean.setPassword(password); + + + if (loginDao.validate(loginBean)) + { + response.sendRedirect("loginSuccess.jsp"); + + } + else { + //HttpSession session = request.getSession(); + response.sendRedirect("login.jsp"); + + } + } + +} \ No newline at end of file diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp index 6059f9b..1f1dadf 100644 --- a/src/main/webapp/login.jsp +++ b/src/main/webapp/login.jsp @@ -11,7 +11,7 @@ - +
User Name:
Password:
-- libgit2 0.26.0