在这种情况下我真的需要帮助,你可以观看我的完整 html 页面以充分理解。
完整 html 页面:http://pastebin.com/zKTmaRxx
我将重点关注其中的一部分来解释我的问题:
<%
if(request.getParameter("type")!=null) {
UserDTO user = new UserDTO();
user.setUsername(request.getParameter("user"));
user.setPassword(request.getParameter("pass"));
if (userDAO.loginUser(user)) {
session = request.getSession(true);
session.setAttribute("user", user.getUsername());
session.setAttribute("type", "admin");
response.sendRedirect("products.jsp");
}
}
%>
我已经调试并看到response.sendRedirect("products.jsp");尽管用户和通行证均已通过验证,但不会将当前页面重定向到我的 products.jsp 页面。
。但是当我把它放出来时,它会毫无问题地重定向 感谢您阅读本文:)
最佳答案
请确保您的 userDAO.login()
函数正常工作并为 if 语句返回 true。
您能否发布userDAO.login()
函数并打印出在这种情况下运行它的结果?
关于java - 为什么 sendRedirect 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7592157/