代码之家  ›  专栏  ›  技术社区  ›  Kaleb Brasee

404 URLMAPPING上未应用Grails布局

  •  4
  • Kaleb Brasee  · 技术社区  · 15 年前

    In a Grails 1.3.1 app, I want 404 errors to cause the render the main index action of the "list" controller. This controller uses a conventional layout file in the layouts directory (views/layouts/list.gsp), which then uses the included snippet for that action (views/list/index.gsp).

    When this action is accessed normally ( http://localhost/list/index ,然后同时应用布局文件和代码段,看起来是正确的。但是,当通过urlmapping类中的404规则访问时——“404”(控制器:“list”,操作:“index”)——不使用布局文件,只显示代码段。

    有人知道为什么会发生这种情况吗?如果有任何方法可以让常规布局显示404(或其他)错误映射?

    3 回复  |  直到 10 年前
        1
  •  1
  •   wwwclaes    15 年前

    Are you sure the layout isn't applied? I'm using Grails 1.3.2 and I 思想 布局没有应用,但实际上是404之后布局中缺少模型和安全标签。

    如果你的布局内容是从这些可用的东西派生出来的,那么先试试“你好世界”看看它是否出现。

        2
  •  5
  •   chrislatimer    15 年前

    我知道前一段时间这是SiteMesh Grails使用的一个bug。有一种方法可以将错误页包装在以下位置:

    <g:applyLayout name="main">  
    </g:applyLayout>
    

    而不是使用通常的:

    <meta name="layout" content="main" />
    
        3
  •  2
  •   Artefacto    10 年前

    Another thing to look for is the sitemesh.xml 配置文件。根据响应的内容类型,将打开/关闭SiteMesh,并且此文件声明将处理的内容类型值。在我的例子中,输入 text/html;charset=UTF-8 对于类型为的响应不够 text/html to be processed.

    推荐文章