[英]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;
}
會話只能在Spring MVC中運行一次,一旦登錄返回首頁,但從首頁到下一個屏幕,則在其他任何控制器中均未找到用戶詳細信息和會話
我有一些建議:
projdet
”。 List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
。 徹底檢查session
變量以查看其是否具有您在登錄時設置的屬性 logout
? 盡管這些可能無法指出確切的解決方案,但可以幫助您找出問題所在。 根據您在問題中提出的內容,沒有證據表明代碼中有任何錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.