FreeMarker 自动转义和格式化HTML和XML输出,预防xss
生活随笔
收集整理的这篇文章主要介绍了
FreeMarker 自动转义和格式化HTML和XML输出,预防xss
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
为什么80%的码农都做不了架构师?>>>
这种自动转义需要FreeMarker 版本大于等于2.3.24。如果你不得不使用一个更早的版本,请使用过时的escape指令替代。
不过考虑到官网上最近的标注2.3.25已经是稳定版,建议升级
Latest stable release: 2.3.25-incubating
Released on 2016-06-26. Requires J2SE 1.5 or higher.
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.25-incubating</version>
</dependency>
所有的以ftlh和ftlx为扩展名的freemarker模板都会自动关联到HTML和XML输出格式,预定义的输出格式如下:
| HTML | Escapes <, >, &, ", ' as <, >, &, ", ' | text/html | HTMLOutputFormat.INSTANCE |
| XHTML | Escapes <, >, &, ", ' as <, >, &, ", ' | application/xhtml+xml | XHTMLOutputFormat.INSTANCE |
| XML | Escapes <, >, &, ", ' as <, >, &, ", ' | application/xml | XMLOutputFormat.INSTANCE |
| RTF | Escapes {, }, \ as \{, \}, \\ | application/rtf | RTFOutputFormat.INSTANCE |
| undefined | Doesn't escape. Prints markup output values (concept explainedlater) from other output formats as is. The default output format used when no output format was explicitly set in the configuration. | None (null) | UndefinedOutputFormat.INSTANCE |
| plainText | Doesn't escape. | text/plain | PlainTextOutputFormat.INSTANCE |
| JavaScript | Doesn't escape. | application/javascript | JavaScriptOutputFormat.INSTANCE |
| JSON | Doesn't escape. | application/json | JSONOutputFormat.INSTANCE |
| CSS | Doesn't escape. | text/css | CSSOutputFormat.INSTANCE |
转载于:https://my.oschina.net/buwei/blog/729857
总结
以上是生活随笔为你收集整理的FreeMarker 自动转义和格式化HTML和XML输出,预防xss的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Redhat Linux通过RPM安装搭
- 下一篇: HTML5 ArrayBufferVi