在grails中使用<set>标记

时间:2016-01-16 03:40:29

标签: grails gsp

我是grails的新手。我遇到了一个 set 标记,我们可以在gsp页面中使用它来设置与控制器中的设置模型类似的值。

<g:set var="home" value="something" />

所以当我们写$ {home}时,它输出“something”。

有没有办法在gsp页面本身的会话中设置值,而不是使用 set 标记从控制器设置?

2 个答案:

答案 0 :(得分:6)

是的,您也可以在gsp页面中执行此操作。您只需要包含一个额外的属性范围,以指示要将值设置为的范围(会话,闪存,页面和请求)。

<g:set var="home" value="something" scope="session" />

如果您不包含范围选项,则默认为page。

要显示您只需编写 $ {session.home} $ {request.home} 或只需 $ {home} <的值/ strong>用于请求范围。希望这可以帮助。

更多信息:https://grails.github.io/grails-doc/3.0.x/ref/Tags/set.html

答案 1 :(得分:0)

嘛!以上答案足以满足需要。只是想在内部添加一个gsp页面由jsp组成的内容,因此gsp页面上也可以使用所有9个implict对象。

request     HttpServletRequest object
response    HttpServletResponse object
out         PrintWriter object used to send output to the client.
session     HttpSession object
application ServletContext object associated with application context.
config      ServletConfig object associated with the page.
pageContext server-specific features JspWriters.
page        synonym for this
Exception   handling exceptions and error page redirects.An instance of javax.servlet.jsp.JspException

您可以随时在gsp页面中访问这些内容。

您可以阅读更多this

希望它有所帮助!