我們使用geronimo-servlet 3.0
和Tomcat 8
運行,這將使用會話如下會議在Java Servlet的每個請求改變3.0
@Service
public class SessionServiceImpl implements SessionService
{
@Autowired(required = false)
private HttpServletRequest request;
private HttpSession session = null;
@Override
public void setUser(User user)
{
session = request.getSession();
if (session != null)
{
session.setAttribute(SessionAttribute.user.name(), user);
}
}
@Override
public void setData(String data)
{
session = request.getSession();
if (session != null)
{
session.setAttribute(SessionAttribute.data.name(), data);
}
}
@Override
public HttpSession getSession()
{
session = request.getSession();
session.setAttribute("TimeoutBased", System.currentTimeMillis());
return session;
}
}
在其他服務的servlet,AuthService,例如,撥打sessionService如下
public class AuthServiceImpl extends CustomizedServlet implements AuthService
{
@Autowired
private SessionService sessionService;
@Override
public BaseModel login(BaseModel user) {
...
sessionService.setUser(userEntity);
...
sessionService.setData(data);
}
}
CustomizedServlet是GWT的com.google.gwt.user.server.rpc.RemoteServiceServlet
。登錄方法是供Web客戶端登錄的。這一切正常工作。
但是,有時候,由於未知原因,會話在來自Google Chrome瀏覽器打開的Web客戶端的每個請求發送時都會發生變化。
此外,在調試模式下,我看到會話Id在一個請求中保持更改,如下圖所示。
如下
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=53144E2C46D6DF7C5986D56F01A6961E; Path=/ABC/; HttpOnly
Content-Encoding: gzip
Content-Disposition: attachment
Content-Type: application/json;charset=utf-8
Content-Length: 1909
Date: Tue, 07 Mar 2017 01:42:13 GMT
爲彗星另一個servlet是第二請求並且在該請求沒有JSESSIONID第一請求響應
GET /ABC/CometServlet?qndOeINh HTTP/1.1
Host: web.test.abc.com:8080
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Content-Type: application/x-javascript;
Accept: */*
Referer: http://web.test.abc.com:8080/ABC/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-TW,zh;q=0.8,ja;q=0.6
Cookie: username=%7B%22state%22%3A%22s%3Aadmin%22%7D;
畢竟,如果我清除鉻的網站數據,它會保持正常工作。尚未弄清楚這種情況的根源。有沒有人有一些經驗或任何想法?