// File: LoginHandler.java // This servlet checks the username and password for validity. // If the client fails the check, they are told that access is denied. // If the client passes, that fact is recorded in their session object // and they are immediately redirected to the original target (obtained // from the Session object). import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class LoginHandler extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // Get the user's name and password String name = req.getParameter("name"); String passwd = req.getParameter("passwd"); // Check the name and password for validity if (!allowUser(name, passwd)) { out.println("