注释行O_o中的异常

时间:2013-01-10 08:41:02

标签: grails

我有这个:

<!--   <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

问题是,显然...... 在一个体面的框架中,一条注释线是否可能抛出异常!!!

1 个答案:

答案 0 :(得分:5)

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

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

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

IE conditional comments

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

GSP评论的语法是

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

GSP解析器会忽略此类评论中的任何内容。