thi is the jsp page
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>SuperMarket Application Login Page</title>
<link rel="stylesheet" type="text/css" href="Login.css">
</head>
<body>
<div class="container">
<h2>Login</h2>
<form action="/login" method="post"> </form>
<div><style padding=10px></style>
<label for"username">Username</label>
<input type="text" id="username" name="u_name" required>
</div>
<div> <style padding = 10px></style>
<label for "password>Password</label>
<input type="password" id="password" name="pass" required>
</div>
<div>
<input type="button" value="Login">
</div>
</form>
</div>
</body>
</html>
This is servlet code to get the attribute
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 java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import operation.dataBaseConnection;
/**
* Servlet implementation class login
*/
public class login extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public login() {
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());
String name=(String) request.getAttribute("u_name");
String pass=(String) request.getAttribute("pass");
System.out.println(name);
System.out.println(pass);
try(Connection conn= dataBaseConnection.get_conn()){
String statement = "SELECT * FROM user WHERE User_name = ? AND User_pass = ?";
try(PreparedStatement preparedstatement = conn.prepareStatement(statement)){
preparedstatement.setString(1, name);
preparedstatement.setString(2, pass);
try(ResultSet resultset = preparedstatement.executeQuery()){
if(resultset.next()) {
response.sendRedirect("Login.html");
}
else {
response.sendRedirect("Login.html");
}
}
}
}
catch(SQLException e){
e.printStackTrace();
response.sendRedirect("Login.html");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
this is my login page I am getting null only when i am running the servlet and not getting the data I am inserting in the form
I am expecting the when i run the servlet it will open on the browser and I will insert data in the form and then when i click on submit button it will get the data and check if the data is not in the database it show an error message and if it matches to any of the data in the database it will work it will log me in