views:

768

answers:

3

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

    session.myVariable = params.myValue

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.

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!

A: 

I could be wrong, but I'm pretty sure Grails uses the sessions associated with your application container. If you're using Tomcat, for example, you can specify the length of a session.

Tutorial for changing Tomcat session length.

Stefan Kendall
+6  A: 

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

grails install-templates

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

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

The value of session-timeout uses minutes as unit.

Stefan
Thanks, Stefan! That's *EXACTLY* what I was looking for. I didn't realize I have to explicitly 'install-templates' to get to web.xml. I'm still a n00b in Grails :)
curd0
A: 

You can have a look at this blog to set session timeout interval through code.

Amit Jain

related questions