这是我的登录 Servlet 的 post 方法
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String login = request.getParameter("login").trim();
String password = request.getParameter("password");
User user = getUsersDao().login(login, DigestUtils.shaHex(password));
if (user == null) {
request.setAttribute("login", login);
request.setAttribute("error", "Wrong username or password.");
forward(request, response, LOGIN_JSP);
} else {
request.getSession().setAttribute(USER_SESSION, user);
response.sendRedirect(LOGGED_IN_URL);
}
}
whereLOGGED_IN_URL is "WEB-INF/jsp/index.jsp";
和 index.jsp 存在于这个地址上,这仅在登录后才起作用。用户的 if 条件是好的(我通过将其设置为 false 来检查它)。
为什么会发生?