@Controller
public class LoginController {
@RequestMapping(value = "showLogin", method = RequestMethod.GET)
public ModelAndView showLogin(HttpServletRequest request, HttpSession session) {
return new ModelAndView("login");
}
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpSession session) {
String page = "login";
String loginId = request.getParameter("loginId");
String password = request.getParameter("password");
// HttpSession session = request.getSession();
session.setAttribute("USERNAME", loginId);
if(loginId.equals("admin") && password.equals("admin")){
session.setAttribute("loginId", "admin");
session.setAttribute("userName", "admin");
session.setAttribute("userDetails", "System Administrator");
session.setAttribute("USERNAME", "admin");
page = "home";
return page;
}
@RequestMapping(value = "projdet", method = RequestMethod.GET)
public String project(
@ModelAttribute("projMaster") ProjectMaster projMaster,
Model model, HttpServletRequest request, HttpSession session) {
List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList();
model.addAttribute("Projlist", allProjectlist);
String page = "project";
return page;
}
会话只运行一次spring mvc,一旦登录返回主页但从家到下一个屏幕没有用户详细信息和任何其他控制器中找不到会话
答案 0 :(得分:0)
我有一些建议:
projdet
”。List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList();
model.addAttribute("Projlist", allProjectlist);
。彻底检查session
变量,看它是否具有您在登录时设置的属性logout
?虽然这些可能没有指出确切的解决方案,但它可以帮助您找出问题所在。根据您在问题中提出的内容,代码中没有任何错误的证据。