我有兩個控制器UserSignInController和PageNavigationController.I想在兩個控制器中保持相同的HttpSession,但我在差異頁面中找到diff會話。我還在控制器中添加了@SessionAttributes(「userDetails」) page.please建議我如何創建這個?維護同一個會話在春天控制器
UserSignInController
@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;
}
PageNavigationController
@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">
你能告訴我你找到了什麼不同嗎?據我所知,所有的控制器是單身人士,所以沒有問題,會話跨越控制器。 – OQJF 2013-03-18 06:50:17