loginAction.js

 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>


<%@ page import="java.sql.*" %>


<!DOCTYPE html>


<html>


<head>


<meta charset="UTF-8">


<title>Login Result</title>


</head>


<body>


<%


String customerId = request.getParameter("customerId");


String password = request.getParameter("password");




// Placeholder for database connection


Connection conn = null;


PreparedStatement pstmt = null;


ResultSet rs = null;




// You need to set up your database connection here


try {


Class.forName("com.mysql.cj.jdbc.Driver"); // Load MySQL driver


conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/yourdatabase", "username", "password");




String sql = "SELECT * FROM customers WHERE customer_id = ?";


pstmt = conn.prepareStatement(sql);


pstmt.setString(1, customerId);


rs = pstmt.executeQuery();




if (rs.next()) {


String storedPassword = rs.getString("password");




if (storedPassword.equals(password)) {


response.sendRedirect("home.jsp");


} else {


out.println("<p>Password not valid</p>");


}


} else {


out.println("<p>ID not valid</p>");


}


} catch (Exception e) {


e.printStackTrace();


out.println("<p>An error occurred. Please try again later.</p>");


} finally {


if (rs != null) try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }


if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }


if (conn != null) try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }


}


%>


<p><a href="login.jsp">Go back to login</a></p>


</body>


</html>

Comments

Popular posts from this blog

fruit.jsp