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

查看:171
本文介绍了如何为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?

预先感谢您的回答!

Thank you in advance for your answers!

推荐答案

另一个选项是修改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天全站免登陆