为什么Internet Explorer没有在请求标头上发送jsessionid cookie?

时间:2018-05-18 12:15:31

标签: java internet-explorer tomcat openshift session-cookies

我正在OpenShift容器上从Oracle iPlanet Web Server迁移到Apache Tomcat。我们的webapp是Apache Struts 2.5,不使用Spring Framework。问题是:由于某种原因,会话无法正常工作,并且仅在Internet Explorer中不起作用。在Mozilla Firefox,Google Chrome和Apple Safari上进行了测试,它运行得很好,只有Internet Explorer面临这个问题。

以下是我的web.xml Cookie会话:

<session-config>
    <session-timeout>30</session-timeout>
    <cookie-config>
        <path>/</path>
    </cookie-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>

我的网络应用程序网址与此类似:

http://app-external-dev-4823.appcloud-np.mycompany.com/APPExternal/

生成的cookie是这样的:

Set-Cookie: JSESSIONID=8A46BC24370545E9885E67D050F25984.Tomcat7-rhel7; Version=1; Path="/"; HttpOnly

我读到Internet Explorer使用_时出现DNS网址问题,但事实并非如此。

比较Google Chrome和Internet Explorer的响应标头,我找不到任何尴尬的内容

谷歌浏览器:

Cache-control:private
Content-Language:en-US
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 18 May 2018 12:08:07 GMT
Server:
Set-Cookie:JSESSIONID=3DC79F0159A3D3324658BD0A644BDE51.Tomcat7-rhel7; Version=1; Path="/"; HttpOnly
Set-Cookie:c4a1aaf48f2245d1880a957d46993e21=8fa84cd57f198140fc034497aab55b2a; path=/; HttpOnly
Set-Cookie:np_cookie=1479619875.20480.0000; path=/
Transfer-Encoding:chunked

Internet Explorer:

Response    HTTP/1.1 200 OK
Set-Cookie  JSESSIONID=3EF94406ED000ACD13A77958B424DDEC.Tomcat7-rhel7;     Version=1; Path="/"; HttpOnly
Content-Type    text/html;charset=ISO-8859-1
Content-Language    en-GB
Transfer-Encoding   chunked
Date    Fri, 18 May 2018 12:06:36 GMT
Server  

我真的把头发拉到这里,大块头发。我试图改变cookie的域名,路径,httponly和安全属性,没有任何变化。顺便说一句,它在本地Apache Tomcat上运行得非常好。

1 个答案:

答案 0 :(得分:2)

这可能不是问题的答案,但是由于评论过多,我在这里发布了解决方案。

我们的服务器也是如此。在本地设置中可以正常工作,但是在生产服务器上就存在此问题。经过大量的时间搜索之后,一个更好,更可靠的解决方案编写了一种处理客户端和服务器之间交互的新方法。基本思想是创建我们的cookie并将该cookie发送给客户端。对于每个请求,这将再次发送回服务器。


    HttpSession session = request.getSession();
    if (request.getParameter("JSESSIONID") != null) {
        Cookie userCookie = new Cookie("JSESSIONID", request.getParameter("JSESSIONID"));
        response.addCookie(userCookie);
    } else {
        String sessionId = session.getId();
        Cookie userCookie = new Cookie("JSESSIONID", sessionId);
        response.addCookie(userCookie);
    }

有关更多信息:Session is lost and created as new in every servlet request