我有两个控制器UserSignInController和PageNavigationController。我想在控制器中保持相同的HttpSession但我在diff页面中找到了一个diff会话。我还在控制器页面中添加了@SessionAttributes(“userDetails”)。请指教我如何我创造了这个?
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">
答案 0 :(得分:0)
您的意思是您将应用程序从一个页面浏览到第二个页面,而第二个页面使用PageNavigationController,而您没有获得相同的会话吗?你如何检查它是否不是同一个会话?您确定在会话中设置了userDetails吗?
同时检查会话cookie是否在请求中正确传递。您可以使用firebug或chrome控制台检查响应和请求标头中的cookie值。
答案 1 :(得分:0)
我找到了答案。此代码编写在context.xml
中<Context path="/sm" docBase="sm"
debug="5" reloadable="true" crossContext="true" cookies="false">
其中cookies =“false”,它应该是cookies =“true”。