这是代码的一部分:
if (results.get(0).equals(username) && results.get(1).equals(password)) {
HttpSession session = request.getSession(false);
if(session != null) {
session.setAttribute("lg_username", results.get(2));
}
response.sendRedirect("/Olapp/index.jsp");
} else {
response.sendRedirect("/Olapp/wrongPassword.jsp");
}
当我登录时,我从来没有被重定向回index.jsp,因为Servlet卡在HttpSession部分(如果我删除它,它会立即重定向)。为什么会这样呢?
编辑:当我使用RequestDispatcher时也会发生同样的情况。
如果这是JSP页面,那么使用session.getSession(false)代替resuest.getSession (false)