现在,JSP遗传下来的缺点已经被取消,下面的章节将涵盖GSP的内置标签,它是定义GSP页面最有利的方法.
标签库 部分涵盖怎么添加你自己的定制标签库.
所有GSP内置标签以前缀g:开始。 不像JSP,你不需要指定任何标签库的导入.
假如,一个标签以g:开始,它被自动认为是一个GSP标签.一个GPS标签的示例看起来像这样:<g:example />
GSP标签同样可以拥有主体,像这样:<g:example>
Hello world
</g:example>
表达式被传递给GSP标签属性,假如没有使用表达式,将被认为是一个String值:<g:example attr="${new Date()}">
Hello world
</g:example>
Maps同样能被传递给GSP标签属性,通常使用一个命名参数样式语法:<g:example attr="${new Date()}" attr2="[one:1, two:2, three:3]">
Hello world
</g:example>
注意,对于String类型属性值,你必须使用单引号:<g:example attr="${new Date()}" attr2="[one:'one', two:'two']">
Hello world
</g:example>