6.2.2.1 变量和作用域 - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith
Version: null
6.2.2.1 变量和作用域
Variables can be defined within a GSP using the set tag:Here we assign a variable called Variables can also be placed in one of the following scopes:
在GSP中,可以通过set标签来定义变量:<g:set var="now" value="${new Date()}" />now to the result of a GSP expression (which simply constructs a new java.util.Date instance). You can also use the body of the <g:set> tag to define a variable:<g:set var="myHTML"> Some re-usable code on: ${new Date()} </g:set>
page- Scoped to the current page (default)request- Scoped to the current requestflash- Placed within flash scope and hence available for the next requestsession- Scoped for the user sessionapplication- Application-wide scope.
scope attribute:<g:set var="now" value="${new Date()}" scope="request" /><g:set var="now" value="${new Date()}" />java.util.Date实例)的结果赋值给now变量。你也可以使用<g:set>标签的主体来定义一个变量:<g:set var="myHTML"> Some re-usable code on: ${new Date()} </g:set>
page- 作用于当前页面(缺省)request- 作用于当前请求flash- 置于flash作用域内,因此在下一个请求中是有效的session- 作用于用户会话application- 应用级别的作用域
scope属性:<g:set var="now" value="${new Date()}" scope="request" />
