html - 为什么 HTML 显示为字符串

标签 html grails

我有一个结果作为列表

[[<a onclick="viewEmpDetails('563291f0af6a1ecb740f904c','false','UniqueId')" title='View' style='cursor:pointer'><i class='ace-icon fa fa-search-plus grey' style='width:30px;'> </i></a>, 02/02/49, 02/02/49, 02/02/1949, 11-Jan-1916, 10-Feb-33]]

我正在使用下面的代码进行迭代

<g:each in="${session.treeGridJsonObject}"  var="lists">
  <g:each in="${lists}"  var="list">
  <td>${list}</td>
  </g:each>
</g:each>   

但是我在 GSP 中得到 html 代码作为字符串。 enter image description here

我如何在 Controller 中添加 html 数据

htmlData += "<a onclick=\"viewEmpDetails('"+row['UniqueId']+"','false','UniqueId')\" title='View' style='cursor:pointer'><i class='ace-icon fa fa-search-plus grey' style='width:30px;'> </i></a>"

当我尝试调试时显示双“”引号。

enter image description here

最佳答案

这是为了防止XSS attacks .这样,如果用户提交了一些 javascript,它不会在显示给其他人时运行。原始数据的输出有多种方式:

${raw(content)}

${content.encodeAsRaw()}

<g:encodeAs codec="Raw">${content}</g:encodeAs>

<g:encodeAs codec="None">${content}</g:encodeAs>

参见 http://mrhaki.blogspot.nl/2013/11/grails-goodness-generating-raw-output.html

关于html - 为什么 HTML 显示为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434216/

相关文章:

html - Div 并排坐成一个正方形

javascript - php代码为互联网上的两个客户端制作实时html Canvas

jquery - 运行此 jquery 脚本时 Safari 和 Chrome 崩溃

php - codeigniter 4 在 include、include_once、require、require_once 之后返回 1

grails - 在 GSP 中将域字段渲染为 HTML?

grails - 将 grails cloud-foundry 与我的 grails 应用程序集成

grails - Grails中的一对一映射

javascript - ThreeJS 中不显示阴影

Grails 分页 : how to use pagination to restrict the number of rows

hibernate - Grails中的悲观锁定3+ lock()