在Web模式下在GWT应用程序中获取会话null,但在托管模式下不会

时间:2011-05-02 09:58:13

标签: spring gwt tomcat6 session-state

我正在运行一个GWT应用程序,它在会话对象中维护用户缓存。我使用的是Spring Security 3.0.5。

以下是我用来获取会话对象的代码

ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpSession session = attr.getRequest().getSession(false);
if(session != null)
     return session;
else
     throw new IllegalStateException("Session Expired");

在托管模式,即jetty服务器,一切正常,我能够检索会话对象,但在Web模式,即tomcat 6,会话对象返回null

我在web.xml中使用以下条目,运行上面的代码

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>

更新

以下是我正在使用的弹簧安全设置

<http>
    <intercept-url pattern="/**Phoenix.html*" access="ROLE_ADMIN"/>
    <form-login authentication-failure-url="/login.html" default-target-url="/Phoenix.html?gwt.codesvr=127.0.0.1:9997" always-use-default-target="true"/>
    <remember-me/>
    <logout />
    <access-denied-handler error-page="/login.html"/>
    <session-management><concurrency-control/></session-management>
</http>

更新

这是因为在登录后的Web模式下 SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()返回“anonymousUser” 在托管模式下,同一表达式返回登录用户的登录凭据。 以下是我正在使用的网址 托管模式:http://127.0.0.1:8888/Phoenix.html?gwt.codesvr=127.0.0.1:9997

网络模式:http://localhost:8185/PhoenixMCDemo/Phoenix.html;jsessionid=E56C80258410D102E6B51EFEE5AA0E91

1 个答案:

答案 0 :(得分:0)

你有enable sessions吗?