Setting the timeout interval of a HttpSession

15 / Apr / 2010 by gaurav 2 comments

In my project, there was a requirement to set the session time out interval and i had no idea about how to implement it. Then my colleague Himanshu Seth came to rescue. This guy has already done it. All you have to do is to set the maximum time out interval in the session. Here is the sample code.

declare a SESSION_TIMEOUT constant in your application constants file (AppConstants.groovy).

public static final Integer SESSION_TIMEOUT = 3600	// This time is set in seconds. 3600 = 1 hour

Now set the maximum inactive interval of session. You need to write this line of code in your controller.

session.setMaxInactiveInterval(AppConstants.SESSION_TIMEOUT);

Hope it helps.

FOUND THIS USEFUL? SHARE IT

comments (2)

  1. Alireza Haghighatkhah

    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:

    60

    The value of session-timeout uses minutes as unit.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *