如何使用grails< g:set>标记会话范围? [英] How to use grails <g:set> tag session scope?
问题描述
我试图在我的gsp上使用g:set标签。只要我在一个页面中,范围是默认或页面,它就可以正常工作。当我尝试将范围更改为会话时,它不起作用。
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.
在全新的2.0.3应用程序中,我的index.gsp正文中包含此脚本,并且按预期工作。
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
这篇关于如何使用grails< g:set>标记会话范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!