在 grails gsp 模板中,如何使用服务器端注释而不导致 sitemesh 抛出错误?

发布于 2024-11-18 13:17:04 字数 146 浏览 3 评论 0 原文

当我在 gsp 模板中使用标准 jsp 注释块时

<%-- some server-side comment --%>    

,sitemesh 会抛出“意外标记”错误。我可以使用其他注释语法吗?

When I use a standard jsp comment block in a gsp template

<%-- some server-side comment --%>    

, sitemesh throws an 'unexpected token' error. Is there another comment syntax I can use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

无尽的现实 2024-11-25 13:17:04

以下对我有用

%{-- <div>hello</div> --}%

The following works for me

%{-- <div>hello</div> --}%
放低过去 2024-11-25 13:17:04

您缺少一个“%”符号。将其写为:

<%-- some server-side comment --%>

You are missing a '%' sign. Write it as :

<%-- some server-side comment --%>
不打扰别人 2024-11-25 13:17:04

之前的答案(以及问题本身)有些混乱,我希望一开始就向我解释。 .gsp 上有几种类型的服务器端注释。
因此,在 .gsp 文档中,服务器端注释如下:

<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head></head>
<body>
    <!-- the basic HTML comment (not on server side) -->
    <h1>Visible on client side</h1>

    <%-- GSP common comment (server side only) --%>
    %{-- GSP alternative approach (again, on server side only) --}%
    <g:if test="${true}">
        <h1>Invisible on client side, just in source code</h1>
    </g:if>

    <p>and the one asked for happens elsewhere, 
    whenever you write classic Groovy script</p>
    <g:set var="myTitle"/>
    <%
        myVar = 'comment'
        if(myVar.equals('comment')){
            /*Needs the classic Java comment, 
            this happens whether you're writing a simple .gsp 
            or any _template.gsp*/
            myTitle = "<h1>Visible on server side only</h1>".encodeAsRaw()
        }
    %>
    ${myTitle}

    <p>.gsp template does not modify comment behaviour</p>
    <g:render template="/templates/myTemplate" model="[:]"/>
</body>
</html>

file: _myTemplate.gsp

<h2>Template</h2>

<!-- visible -->
<% invisible %>
%{-- invisible --}%
<% /*invisible*/ %>

(Grails 2.5.5)

There's a little confusion among previous answers (and the question itself) that I wish was explained to me at first. There are a few types of server side comments on a .gsp.
So within the .gsp document Server side comments go as follow:

<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head></head>
<body>
    <!-- the basic HTML comment (not on server side) -->
    <h1>Visible on client side</h1>

    <%-- GSP common comment (server side only) --%>
    %{-- GSP alternative approach (again, on server side only) --}%
    <g:if test="${true}">
        <h1>Invisible on client side, just in source code</h1>
    </g:if>

    <p>and the one asked for happens elsewhere, 
    whenever you write classic Groovy script</p>
    <g:set var="myTitle"/>
    <%
        myVar = 'comment'
        if(myVar.equals('comment')){
            /*Needs the classic Java comment, 
            this happens whether you're writing a simple .gsp 
            or any _template.gsp*/
            myTitle = "<h1>Visible on server side only</h1>".encodeAsRaw()
        }
    %>
    ${myTitle}

    <p>.gsp template does not modify comment behaviour</p>
    <g:render template="/templates/myTemplate" model="[:]"/>
</body>
</html>

file: _myTemplate.gsp

<h2>Template</h2>

<!-- visible -->
<% invisible %>
%{-- invisible --}%
<% /*invisible*/ %>

(Grails 2.5.5)

雪花飘飘的天空 2024-11-25 13:17:04

最初的问题是询问如何注释掉 GSP 文件中的任何内容。唯一对我有用的是

<%-- some code to comment out --%>

其他答案将不起作用,特别是如果被注释的代码是 grails 标签。 %{ 和 <% 不起作用。

The original question was asking how to comment out anything in the GSP file. The only one that worked for me is

<%-- some code to comment out --%>,

the other answers won't work especially if the code being commented are grails tags. %{ and <% didn't work.

秋意浓 2024-11-25 13:17:04

常规的 java 注释块就可以工作

<% /*  some server side comment */ %>

A regular java comment block will work

<% /*  some server side comment */ %>
甜味拾荒者 2024-11-25 13:17:04

如果您正在编写一个想要显示未解释的 grails g: 标记的 gsp,例如您希望 ...按原样显示在页面上,无需在服务器端进行解释,以下内容对我来说效果很好。

在开始和结束标记中,将 < 替换为 <

,例如

... /g:link> 在服务器端进行解释并在页面中显示链接。

... 在前端页面中显示为 ...

if you are writing a gsp that wants to display a uninterpreted grails g: tag, e.g. you want <g:link ... to appear as-is on the page, without being interpreted server-side, the following worked nicely for me.

In both the start and end tags, replace the < with <

e.g.

<g:link...>...</g:link> gets interpreted server-side and shows up in the page a link.

<g:link ...>...</g:link ...> shows up in the front-end page as <g:link...>...</g:link>

隱形的亼 2024-11-25 13:17:04

<%-- 服务器端代码 --%> 应该可以工作

<%-- server side code --%> should work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文