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="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 follows 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("home"); // Home page?
} else {
response.sendRedirect("error"); // Error page? You can eventually redisplay same JSP with error message.
}
Finally map this servlet in web.xml like:
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>myservlets.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
Which means that you can invoke it by http://example.com/webapp/login as done in <form action>
.
When learning JSP/Servlet I recommend the following resources:
JSP/Servlet tutorial at sun.com.
JSP/Servlet tutorials at coreservlets.com.
Head First Servlets & JSP.
Good luck.