我有两个控制器 UserSignInController 和 PageNavigationController。我想在两个控制器中维护相同的 HttpSession,但我在 diff 页面中找到了一个 diff 会话。我还在控制器页面中添加了 @SessionAttributes("userDetails")。请告诉我如何创建这个?
用户登录控制器
@RequestMapping(value="/analyzeinternet1.html", method=RequestMethod.GET)
public ModelAndView getSocialMediaAdmin(HttpSession session, Model model) {
LOG.info(" session..." + session);
ModelAndView mv = null;
UserProfile up = (UserProfile) session.getAttribute("userDetails");
if(up == null) { //Checking whether the user is already signed up or not. If not, the user is redirected to login page.
LOG.info("No user in session...");
mv = new ModelAndView("redirect:/login.html");
} else {
LOG.info("User in session..." + up);
mv = new ModelAndView("internetanalyze");
model.addAttribute("userDetails", up);
session.setAttribute("userDetails", up);
mv.addObject("clientId", up.getUserId());
}
LOG.info(mv);
return mv;
}
页面导航控制器
@RequestMapping(value="/analyzeinternet.html", method=RequestMethod.GET)
public ModelAndView getAnalyzeInternet(HttpSession session, Model model) {
LOG.info("-----session..." + session);
//LOG.info("-----userprofile..." + userDetails);
ModelAndView mv = null;
up = (UserProfile) session.getAttribute("userDetails");
LOG.info("User in session..." + up);
mv = new ModelAndView("internetanalyze");
//mv.addObject("clientId", up.getUserId());
return mv;
}
两个会话 id 都不同,我的重定向代码是
<a href="<%=request.getContextPath()%>/analyzeinternet.html">