【问题标题】:sessionCookiePath attribute doesn't work on my tomcat7 serversessionCookiePath 属性在我的 tomcat7 服务器上不起作用
【发布时间】:2014-04-15 23:30:45
【问题描述】:

我在我的 tomcat 服务器上部署了两个 web 应用程序,我希望它们可以相互共享会话数据。所以我在 context.xml 文件的 Context 标签中添加了一个属性 sessionCookiePath="/" 。但是重启服务器后,还是设置了应用路径的cookie,比如“Set-Cookie: JSESSIONID=7200fce5-8aee-4d95-b4d8-4ab586dba152; Path=/webapp1; HttpOnly”!

tomcat服务器版本为7.047。

这是我的 context.xml 的内容

<Context sessionCookiePath="/"><WatchedResource>WEB-INF/web.xml</WatchedResource></Context>

这里是 server.xml

<Server port="8005" shutdown="SHUTDOWN"><Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>

之后,我尝试在应用程序中使用 web.xml 解决这个问题,添加了 cookie-config 标签,但它仍然不起作用。

这是 web.xml

<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>imeapcore</display-name><session-config>
<cookie-config>
    <path>/</path>
</cookie-config></session-config>
<listener>
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>nutz</filter-name>
    <filter-class>org.nutz.mvc.NutFilter</filter-class>
    <init-param>
        <param-name>modules</param-name>
        <param-value>com.imeap.webservice.MainModule</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>nutz</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

【问题讨论】:

    标签: java session tomcat cookies config


    【解决方案1】:

    我明白了。

    我使用 shiro 管理会话信息而不是 tomcat 本身,因此省略了“sessionCookiePath”属性。这个要在shiro.ini中设置,如:

    sessionIdCookie=org.apache.shiro.web.servlet.SimpleCookie
    sessionIdCookie.name=sid  
    sessionIdCookie.path=/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 2016-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多