【问题标题】:GWT application, Session doesnt expire - is this right?GWT 应用程序,会话不会过期 - 对吗?
【发布时间】:2012-02-08 18:43:21
【问题描述】:

我正在编写我的第一个 GWT 应用程序,并且正在实施会话。

目前我正在生成一个

HttpServletRequest request = getThreadLocalRequest();
HttpSession httpSession = request.getSession(true);
httpSession.setMaxInactiveInterval(1000 * 60 * 2);//2min 

然后在显示任何屏幕之前通过对服务器的 RPC 调用验证会话是否与用户相同

HttpServletRequest request = getThreadLocalRequest();
HttpSession httpSession = request.getSession(false);

if(user.getSessionId().equals(result.getSessionId()))
    //display screen

我的问题是关于 setMaxInactiveInterval();非活动超时似乎根本不适合我 - 两分钟后会话不会自行到期

我的方法正确吗?谢谢。

附言我用这个作为跳出:http://snipt.net/javagner/session-in-gwt/

【问题讨论】:

  • 我也尝试使用会话超时中的数字,1*60 等
  • 您链接到的代码是否有任何文档?我想更详细地了解为什么选择这种方法。

标签: session gwt


【解决方案1】:

web.xml中一般都有这个

  <session-config>
    <session-timeout>30</session-timeout> <!-- 30 minutes -->
  </session-config>

【讨论】:

  • 我仍然没有解决问题,但似乎 web.xml 配置和 setMaxInactiveInterval() 方法确实是配置会话的两种方式。一定是其他的问题..
【解决方案2】:
httpSession.setMaxInactiveInterval(1000 * 60 * 2);//2min 

这不是 2 分钟,而是 2000 分钟。

https://docs.oracle.com/javaee/6/api/index.html?javax/servlet/http/HttpSession.html

javax.servlet.http.HttpSession.setMaxInactiveInterval(int 间隔)

指定客户端请求之间的时间,以秒为单位 servlet 容器将使该会话无效。

【讨论】:

    猜你喜欢
    • 2012-02-05
    • 2011-11-28
    • 2013-06-05
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多