grails - O_o注释行中的异常

标签 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

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

最佳答案

因为<!--在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解析器将忽略此类注释中的任何内容。

关于grails - O_o注释行中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14253762/

相关文章:

grails - 如何根据环境做一些URL映射?

grails - chrome中的Geb单选按钮不起作用

grails - 通过Grails中的终端删除服务

grails - 生成的 Controller 的更新方法中的version参数是什么

java - Groovy/Grails代码的JDB调试

exception - 清除自定义异常的消息

eclipse - 在Eclipse中突出显示某些单词

grails - 如何在grails域类中获取hasMany实例属性的平均值?

java - Controller 单元测试如何使用返回类型 ValueOperations 模拟 RedisTemplate opsForValue

Tomcat 无法启动应用程序并超时——日志中的最后一行只是单词 "bad"