SShehab
SShehab

Reputation: 1051

Setting session variable in Grails controllers

I'm using Grails 2.5.1 i'm trying to set session variable in a controller and checking it in another controller but the variable came with null value

Here is the controller i set the session variable in :

def setSessionForHR() {

        session.isCallingHR='true'

    }

in the below controller i check the value but the value is null:

println( "check : $session.isCallingHR  ") // here i get null   
 if (session.isCallingHR=='true')
    {
       //do something
     }

am i missing something ?

Thanks

Upvotes: 0

Views: 2632

Answers (1)

leen
leen

Reputation: 11

def setSessionForHR() 
{

//session.isCallingHR='true'
session["isCallingHR"]='true'

}

------------------------------------------

println(session["isCallingHR"])    
def isCallingHR=session["isCallingHR"]
if (isCallingHR)
{
   //do something
}

-----------------------------------------

pls refer following link for more info http://docs.grails.org/3.1.1/ref/Servlet%20API/session.html

Upvotes: 1

Related Questions