Commit 7dfecacd by Emanuel Lugo

Merge branch 'elugo' into 'develop'

Elugo

See merge request jbaez/ProyectoFinal-Bootcamp!10
parents e14c1af2 e3218568
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="Encoding"> <component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -2,8 +2,8 @@ package com.roshka.proyectofinal; ...@@ -2,8 +2,8 @@ package com.roshka.proyectofinal;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import javax.servlet.*; import jakarta.servlet.*;
import javax.servlet.http.*; import jakarta.servlet.http.*;
public class ProtectedResource extends HttpServlet { public class ProtectedResource extends HttpServlet {
......
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;
}
}
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 ;
}
}
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
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>BootcampsLogin</title>
</head>
<body>
<div align=" center">
<h1>User Login Form</h1>
<form action="login" method="post">
<table>
<tr><td>User Name:</td> <td><input type="text" name = "username"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
<tr><td><input type="submit" value="Login"/></td></tr>
</table>
</form>
</div>
</body>
</html>
\ No newline at end of file
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>LoginExitoso</title>
</head>
<body>
<div align = "center">
<h1>LOGGIN EXITOSO</h1>
</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