grails 呈现html ckeditor

Grails框架,用ckeditor获取的用户编辑的富文本,需要呈现出来,中有如下问题:

1、恶意代码危险:

当呈现HTML文件或XHTML文件时,你必须对每个对象调用encodeAsHTML().

2、如何呈现为html,而非源代码。

如一段文本<a href=www.baidu.com>百度</a>,想呈现成      百度

方法1、在gsp中直接使用${content}会呈现源代码,应该使用${raw(content)} ,或者<%=expression%>(这个方式不推荐,2.4.x版本中已经是deprecated)。

方法2、Config.groovy中加入如下配置  grails.views.default.codec='html'(默认等于none),则直接使用${content}可以转义成html

http://stackoverflow.com/questions/11674344/how-do-i-save-and-display-html-in-grails-using-the-ckeditor

3、可能会有乱码的问题

posted on 2015-03-10 16:27  xhyper  阅读(313)  评论(0编辑  收藏  举报

导航