@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
private UserService userService = new UserServiceImpl();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
String remember = request.getParameter("remember");
if (remember != null && "remember-me".equals(remember)) {
Cookie cookie_username = new Cookie("username", username);
Cookie cookie_password = new Cookie("password", password);
response.addCookie(cookie_username);
response.addCookie(cookie_password);
}
User user_login = userService.findUser(username, password);
if (user_login != null && !user_login.equals("")) {
response.setContentType("text/html;charset=utf-8");
response.sendRedirect(request.getContextPath() + "/success.html");
} else {
response.setContentType("text/html;charset=utf-8");
response.sendRedirect(request.getContextPath() + "/error.html");
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
|
|