Commit 38ca486a authored by Fabian Dewantara Santonie's avatar Fabian Dewantara Santonie 🕊

Test Alert

parent 50235031
......@@ -17,49 +17,53 @@ import javax.servlet.http.HttpSession;
@WebServlet("/halamanLogin")
public class halamanLogin extends HttpServlet {
private static final long serialVersionUID = 1L;
public halamanLogin() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
public halamanLogin() {
super();
// TODO Auto-generated constructor stub
}
@SuppressWarnings("deprecation")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Greetings</title>");
out.println("</head>");
out.println("<body>");
out.println("<script>");
out.println("alert('Username or Password Invalid')");
out.println("</script>");
out.println("</body>");
out.println("</html>");
response.sendRedirect(request.getContextPath() + "/Login.jsp");
}
@SuppressWarnings("deprecation")
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Connection con = DatabaseConnection.initializeDatabase();
Statement stmt = (Statement) con.createStatement();
ResultSet rs = stmt.executeQuery("select * from tbl_user where email = '" +request.getParameter("email").toString() + "' and password = '" +request.getParameter("password")+"'");
ResultSet rs = stmt
.executeQuery("select * from tbl_user where email = '" + request.getParameter("email").toString()
+ "' and password = '" + request.getParameter("password") + "'");
rs.next();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String emailLog = request.getParameter("email");
String passwordLog = request.getParameter("password");
if(passwordLog.equals(rs.getString("password")) && emailLog.equals(rs.getString("email"))) {
if (emailLog.equalsIgnoreCase(rs.getString("email")) && passwordLog.equals(rs.getString("password"))) {
HttpSession session = request.getSession(true);
session.putValue("nama", rs.getString("nama"));
session.putValue("email", rs.getString("email"));
response.sendRedirect(request.getContextPath() + "/menuAwal");
}
else {
out.println("<html>");
out.println("<head>");
out.println("<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Audiowide\">");
out.println("<style>");
out.println("body { font-family: \"Audiowide\", sans-serif;}");
out.println("</style>");
out.println("</head>");
out.println("<body>");
out.println("Username/Password Salah");
out.println("<br>");
out.println("<a href=\"Login.jsp\">Kembali Login</a>");
out.println("</body>");
out.println("</html>");
} else {
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
response.sendRedirect(request.getContextPath()+"/Login.jsp");
}
doGet(request, response);
//response.sendRedirect(request.getContextPath() + "/Login.jsp");
}
}
}
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