我目前正在使用db(mysql)来存储我的春季会话。它正在为每个用户生成新的会话ID,但它正在替换以前记录的会话ID。请提出一些建议来克服这个问题。 以下是我从控制器为每个请求调用的服务
public class MultiLoginServiceImpl
{
public static String createMultiLogin(HttpServletRequest httpRequest)
{
String alias = httpRequest.getParameter("_s");
System.err.println("alias"+alias);
@SuppressWarnings("unchecked")
SessionRepository<Session> sessionRepository =(SessionRepository<Session>) httpRequest.getAttribute(SessionRepository.class.getName());
Map<String, String> sessionIds = sessionManager.getSessionIds(httpRequest);
System.out.println(sessionIds);
for(Map.Entry<String, String> entry : sessionManager.getSessionIds(httpRequest).entrySet()) {
String aliasId = entry.getKey();
String sessionId = entry.getValue();
HttpSession httpSession = httpRequest.getSession(false);
Session storedSession = sessionRepository.getSession(sessionId);
if(storedSession.getAttribute("userEmailId")!= null)
{
httpSession.setAttribute("userEmailId", storedSession.getAttribute("userEmailId"));
}
System.out.println("mapids"+aliasId +" : "+sessionId);
}
String addAlias = alias== null ? newSessionAlias1: requestedSessionAlias1;
/*if(alias == null || "".equals(alias.trim()))
{
alias = sessionManager.getNewSessionAlias(httpRequest);
}*/
httpRequest.setAttribute("alias",addAlias);
//SecurityContext context = (SecurityContext) httpSession.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
//System.out.println(context.toString());
String addAccountUrl = sessionManager.encodeURL(httpRequest.getContextPath(), addAlias);
System.out.println("addalias"+addAlias);
return addAccountUrl ;
}
}