Unlike PHP, you normally use JSP for presentation only. Despite the fact you can write Java code in a JSP file using scriptlets (the <% %> things with raw Java code inside), you should be using (either directly or indirectly) a servlet class to control requests and execute business logic. You can use taglibs in JSP to generate/control the output. A standard taglib is JSTL, with the JSTL 'core' being the most important. You can use EL (Expression Language) to access data which is available in page, request, session and application scopes.
To start, create a JSP file which contains basically the following:
<form action="${pageContext.request.contextPath}/login" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit">
</form>
Then create a servlet class which has the doPost() as below implemented:
String username = request.getParameter("username");
String password = request.getParameter("password");
User user = userDAO.find(username, password);
if (user != null) {
request.getSession().setAttribute("user", user); // Logged in!
response.sendRedirect(request.getContextPath() + "/home"); // Redirect to some home page.
} else {
request.setAttribute("message", "Unknown login, try again."); // Print it in JSP as ${message}.
request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response); // Redisplay same JSP with error message.
}
Finally annotate the servlet class as below:
@WebServlet("/login")
Which means that you can invoke it by http://example.com/webapp/login as done in <form action>.
See also:
Good luck.