In this hands-on you have to create a Login Servlet that accepts user email and password and display a welcome message using a Welcome Servlet if the user details are present in the database.
Solution Code -
//DbConnection.java
package com.fresco.login;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbConnection {
public static Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:h2:mem:testdb", "sa", "");
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
public static void closeConnection(Connection con) {
try {
con.close();
} catch (Exception e) {
}
}
}
// LoginServlet.java
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Login")
For complete Solution please Purchase the solution.
TCS HackerRank Java Developer JSP,Servlet Solution
Solution is given in PDF file. You will Get all the required code in Java to qualify your exam with 100% security.