以下是代码的一部分:
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时会发生同样的情况。
答案 0 :(得分:0)
如果这是JSP页面,则使用session.getSession(false)代替 resuest.getSession(假)