1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| @WebServlet(name = "LoginServlet", urlPatterns = "/login") public class LoginServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); if ("root".equals(username) && "1234".equals(password)) { User user = new User(); user.setUsername(username); user.setPassword(password); request.getSession().setAttribute("existUser", user); response.sendRedirect("/demo/showIndex"); } else { request.getRequestDispatcher("/demo/login.html").forward(request, response); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } }
|