Q:

request.getAttribute return null from HTML

I wrote a login HTML and submit the username, password to the servlet
@WebServlet(name = "loginServlet")
public class loginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("post");
        Enumeration enumeration = request.getAttributeNames();
        while (enumeration.hasMoreElements()) {
            System.out.println(enumeration.nextElement());
        }
        String username = (String) request.getAttribute("username");
        String password = (String) request.getAttribute("password");
        System.out.println(username);
        System.out.println(password);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}

My HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
</head>
<body>

<h1>Login</h1>

<form action="/loginServlet" method="post">
    User Name: <input required name="username" value="name">
    Password: <input required type="password" name="password" value="pw">
    <input type="submit" value="Submit">
</form>

</body>
</html>

The output of the servlet is:
post
null
null
I checked the request.getAttribute returning null in servlet
But that situation is JSP, not HTML.
Are there anything wrong? Or can I use the HTML instead of the JSP to get the username and password?

A:

For login page use below code :

    <form action="servlet1" method="post">
    Name:<input type="text" name="username"/><br/><br/>
    Password:<input type="password" name="userpass"/><br/><br/>
    <input type="submit" value="login"/>
    </form>
and to get attribute of that form create a class and write the below code :
public class FirstServlet extends HttpServlet {  
public void doPost(HttpServletRequest request, HttpServletResponse response)  
    throws ServletException, IOException {  

response.setContentType("text/html");  
PrintWriter out = response.getWriter();  

String n=request.getParameter("username");  
String p=request.getParameter("userpass");  

}  
}  

