简体   繁体   中英

How to use grails <g:set> tag session scope?

I am trying to use the g:set tag on my gsp. As long as I am in one page and the scope is default or page, it works fine. When I am trying to change the scope to session its not working.

My understanding is I should be able to access that variable not only on that page but also on others when the scope is session, however, I might be wrong.

In a brand new 2.0.3 application I have this script on my index.gsp body and it works as expected.

<g:set var="bar" value="${new Date() - 7}" scope="page" />
<div class="message" role="status">${bar}</div>

However if I change the scope to session it doesn't work,

    <g:set var="bar" value="${new Date() - 7}" scope="session" />
    <div class="message" role="status">${bar}</div>

neither on any other page.

Have you tried:

<div class="message" role="status">${session.bar}</div>

http://grails.org/doc/latest/guide/theWebLayer.html#variablesAndScopes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM