Assignment no 3
Name : Badal Madhukar Gaurkhede
PRN NO : 122B1B085
Code :
1) [Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
String email = [Link]("user_email");
String password = [Link]("user_password");
[Link](email + " " + password);
User user = new User();
[Link](email);
[Link](password);
UserDao dao = new UserDao();
User user1 = [Link](user);
if(user1 != null) {
[Link]("Yes");
HttpSession session = [Link]();
[Link]("userD", user1);
[Link]("[Link]");
} else {
HttpSession session = [Link]();
[Link]("login-failed", "Invalid username or
password");
[Link]("[Link]");
}
}
}
2) [Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<h1>Login</h1>
<%
String login_invalid = (String) [Link]("login-failed");
if (login_invalid != null) {
%>
<div role="alert"><%=login_invalid%></div>
<%
[Link]("login-failed");
}
%>
<%
String withoutLogin = (String) [Link]("login-error");
if (withoutLogin != null) {
%>
<div role="alert"><%=withoutLogin%></div>
<%
[Link]("login-error");
}
%>
<%
String logoutMsg = (String) [Link]("logout-msg");
if(logoutMsg != null) {
%>
<div class="alert alert-success" role="alert"><%=logoutMsg %></div>
<%
[Link]("logout-msg");
}
[Link]("Badal");
%>
<form action="login" method="post">
<label>Enter Email</label> <input type="email" class="form-control"
id="email1" name="user_email">
<br><br>
<label>Enter Password</label> <input type="password"
class="form-control" id="pass1" name="user_password">
<br><br>
<button type="submit">Login</button>
</form>
<br><hr><br>
<p class="text-center text-white">Note: If any issue then contact
badalgaurkhede@[Link]</p>
<p class="text-center text-white">Designed by Badal Gaurkhede</p>
<p class="text-center text-white">All rights reserved
@BadalGaurkhede-2024</p>
</body>
</html>
3) [Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class UserDao {
private Connection con;
public UserDao() {
try {
[Link]("[Link]");
con =
[Link]("jdbc:mysql://localhost:3306/pccoe", "root",
"0703");
} catch(Exception e) {
[Link]();
[Link]("error");
}
[Link](con);
}
public User loginUser(User user) {
User user1 = null;
try {
String query = "select * from user where email=? and
password=?";
PreparedStatement pst = [Link](query);
[Link](1, [Link]());
[Link](2, [Link]());
[Link]([Link]() + " " +
[Link]());
ResultSet rs = [Link]();
if([Link]()) {
[Link]([Link]("id"));
user1 = new User();
[Link]([Link]("id"));
[Link]([Link]("name"));
[Link]([Link]("email"));
[Link]([Link]("password"));
}
} catch(Exception e) {
[Link]();
}
return user1;
}
}
4) [Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home Page</title>
</head>
<%@ page import="[Link]" %>
<body>
<%
User user = (User) [Link]("userD");
String name = [Link]();
String email = [Link]();
String password = [Link]();
%>
<h1>Welcome <%= name %> !!</h1>
<h3>Your Details :</h3>
<h3>Email :<%= email %> Password: <%= password %></h3>
</body>
</html>
Output :