gpt4 book ai didi

java - 在 Spring Controller 中维护相同的 session

转载 作者:行者123 更新时间:2023-12-01 04:48:07 24 4
gpt4 key购买 nike

我有两个 Controller UserSignInController 和 PageNavigationController。我想在两个 Controller 中维护相同的 HttpSession,但我在 diff 页面中发现了 diff session 。我还在 Controller 页面中添加了 @SessionAttributes("userDetails")。请告诉我如何操作我创建了这个?

用户登录 Controller

@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;
}

页面导航 Controller

@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;
}

两个 session ID 不同,我的重定向代码是

<a href="<%=request.getContextPath()%>/analyzeinternet.html">

最佳答案

您的意思是您从一页浏览应用程序到第二页,并且第二页使用 PageNavigationController,但您没有获得相同的 session ?您如何检查它是否不是同一个 session ?您确定在 session 中设置了 userDetails 吗?

还要检查 session cookie 是否在请求中正确传递。您可以使用firebug或chrome控制台检查响应和请求 header 中的cookie值。

关于java - 在 Spring Controller 中维护相同的 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15470679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com