如何为 Grails 应用程序配置会话超时? [英] How to configure a session timeout for Grails application?

查看:45
本文介绍了如何为 Grails 应用程序配置会话超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Grails 应用程序中的一个控制器中,我在会话变量中保留了一个参数值,如下所示:

In one of controllers in my Grails application I'm preserving a parameter value in a session variable like this:

session.myVariable = params.myValue

之后,只要我主动使用该应用程序,我就可以从不同的控制器/GSP 页面访问保存的值.但是,如果我有一段时间不使用我的应用程序,即使我的浏览器窗口仍然打开,会话变量也会失去它的值.

After that, I can access the saved value from different controllers/GSP-pages as long as I actively use the app. However, if I don't use my app for a while, even though my browser window is still open, the session variable looses it's value.

这是因为会话过期吗?我的印象是会话一直持续到浏览器窗口仍然打开,但显然我错了.

Does this happens because the session expires? I was under impression that a session lives until the browser window is still open, but apparently I was wrong.

我应该怎么做才能确保我在 Grails 应用程序中定义的所有会话变量在浏览器关闭之前不会过期?有没有办法手动设置会话超时?

What should I do to ensure all session variables I define in my Grails app don't expire until the browser is closed? Is there any way to set session timeout manually?

预先感谢您的回答!

推荐答案

另一个选项是修改 web.xml.之前你必须打电话

Another option would be modifying web.xml. Prior you must call

grails install-templates

然后编辑 src/templates/war/web.xml 并在 servlet-mapping 后添加/修改:

Then edit src/templates/war/web.xml and add/modify after servlet-mapping:

<session-config>
   <session-timeout>60</session-timeout>
</session-config>

session-timeout 的值以分钟为单位.

The value of session-timeout uses minutes as unit.

这篇关于如何为 Grails 应用程序配置会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆