1

我有这个:

<!--   <div class="fieldcontain ${hasErrors(bean: azafataInstance, field: 'localidad', 'error')} required" style="margin-left: 10px">-->
<!--<label for="localidad">Localidad</label>    -->
<!--<g:if test="${params?.localidad }">-->
<!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${[' ',params.localidad]}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px" />-->
<!--</g:if>-->
<!--<g:else>-->
<!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${['']}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px"  />-->
<!--</g:else>-->
<!--</div>-->

如您所见...行已注释。我运行这个项目,我得到了这个:

URI
/com.publidirecta.azafatas/azafataCertificada/registro_page
Class
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
Message
Tag [else] cannot have non-whitespace characters directly preceding it.

Around line 95 of grails-app/views/azafataCertificada/registro.gsp

92:<!--<g:if test="${params?.localidad }">-->
93:<!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${[' ',params.localidad]}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px" />-->
94: <!--</g:if>-->
95: <!--<g:else>-->
96: <!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${['']}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px"  />-->
97:<!--</g:else>-->
98:<!--</div>-->

Trace

Line | Method
->> 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   908 | run     in     ''
^   680 | run . . in java.lang.Thread

Caused by GrailsTagException: Tag [else] cannot have non-whitespace characters directly preceding it.
->>  95 | runTask in /grails-app/views/azafataCertificada/registro.gsp

显然,问题是……在一个体面的框架中,注释行怎么可能引发异常!!!

4

1 回答 1

5

因为<!--不是 GSP 中的评论。

正如您所发现的,GSP 解析器将 HTML 样式的注释视为普通内容,以便生成包含 HTML 注释的输出,例如在脚本标签中

<script type="text/javascript><!--
js goes here;
//--></script>

IE 条件注释

<!--[if IE 6]>
<script type="text/javascript" src="${resource(dir:'css', file:'ie6-fixup.js')}"></script>
<![endif]-->

GSP 注释的语法是

<%-- this is commented out --%>

GSP 解析器将忽略此类注释中的任何内容。

于 2013-01-10T09:02:00.580 回答