Grails 使用<;设置>;圣杯中的标签

Grails 使用<;设置>;圣杯中的标签,grails,gsp,Grails,Gsp,我不熟悉grails。我遇到了一个set标记,我们可以在gsp页面本身中使用它来设置值,这类似于从控制器设置模型 <g:set var="home" value="something" /> 因此,当我们编写${home}时,它会输出“某物” 是否有任何方法可以在gsp页面本身的会话中设置值,而不是使用set标记从控制器中设置值?是的,您也可以在gsp页面中进行设置。您只需包含一个额外的属性scope,以指示要将值设置为哪些作用域(会话、闪存、页面和请求) <g:set

我不熟悉grails。我遇到了一个set标记,我们可以在gsp页面本身中使用它来设置值,这类似于从控制器设置模型

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

因此,当我们编写${home}时,它会输出“某物”


是否有任何方法可以在gsp页面本身的会话中设置值,而不是使用set标记从控制器中设置值?

是的,您也可以在gsp页面中进行设置。您只需包含一个额外的属性scope,以指示要将值设置为哪些作用域(会话、闪存、页面和请求)

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

如果不包括范围选项,则默认为第页

要显示该值,只需为请求范围写入${session.home}${request.home}或只需写入${home}。希望这有帮助


更多信息:

好!以上答案足以满足需要。只是想再添加一个东西,gsp页面内部由jsp组成,因此所有9个隐式对象也可以在gsp页面上使用

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页面中访问这些内容

更多你可以阅读的内容

希望有帮助