[英]Session only works one time spring mvc,
@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;
}
Session only works one time spring mvc,once login returns home page but from home to next screen no user details and session not found in any other controller 会话只能在Spring MVC中运行一次,一旦登录返回首页,但从首页到下一个屏幕,则在其他任何控制器中均未找到用户详细信息和会话
I have a few suggestions: 我有一些建议:
projdet
". projdet
”。 List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
. session
variable thoroughly to see if it has the attributes you set on login session
变量以查看其是否具有您在登录时设置的属性 logout
? logout
? While these may not point out the exact solution, it may help you figure out the issue. 尽管这些可能无法指出确切的解决方案,但可以帮助您找出问题所在。 From what you have presented in the question, there is no evidence of anything wrong in the code.
根据您在问题中提出的内容,没有证据表明代码中有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.