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

本秂侑毒 提交于 2019-12-11 06:56:43

问题


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.


回答1:


Have you tried:

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

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



来源:https://stackoverflow.com/questions/10143159/how-to-use-grails-gset-tag-session-scope

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!