tw.com.javaworld.CH11.LoginChecker (Java2HTML)

| LoginChecker.java |

    1 package tw.com.javaworld.CH11;
    2
    3 import java.io.*;
    4 import javax.servlet.*;
    5 import javax.servlet.http.*;
    6
    7 public class LoginChecker extends HttpServlet {
    8
    9     protected void doPost(
    10        HttpServletRequest httpRequest,
    11        HttpServletResponse httpResponse) throws IOException, ServletException {
    12
    13        String userId = httpRequest.getParameter("userId");
    14        String password = httpRequest.getParameter("password");
    15        String targetURI = httpRequest.getParameter("originalURI");
    16
    17        if ((!userId.equals("admin")) || (!password.equals("1234"))) {
    18            throw new ServletException("»{ÃÒ¥¢±Ñ");
    19        }
    20
    21        HttpSession session = httpRequest.getSession();
    22        session.setAttribute("passed", "true");
    23        httpResponse.sendRedirect(targetURI);
    24    }
    25}