【问题标题】:using <set> tag in grails在 grails 中使用 <set> 标签
【发布时间】:2016-01-16 03:40:28
【问题描述】:

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

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

这样当我们编写 ${home} 时,它会输出“某物”。

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

【问题讨论】:

    标签: grails gsp


    【解决方案1】:

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

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

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

    要显示值,您只需编写 ${session.home}${request.home} 或简单地 ${home} 用于请求范围。希望这可以帮助。

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

    【讨论】:

      【解决方案2】:

      好吧!上面的答案就足够了。只是想再添加一件 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 页面中访问这些内容。

      您可以从this阅读更多内容。

      希望对你有帮助!

      【讨论】:

        猜你喜欢
        • 2011-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多