`
cuker919
  • 浏览: 88831 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Velocity模板引擎下 velocity.properties转义(转码)配置

 
阅读更多

velocity配置文件中的编码配置类:

//对html文件编码的配置
org.apache.velocity.app.event.implement.EscapeHtmlReference
//对javascript文件编码的配置
org.apache.velocity.app.event.implement.EscapeJavascriptReference
//对sql文件编码的配置
org.apache.velocity.app.event.implement.EscapeSqlReference
//对xml文件编码的配置
org.apache.velocity.app.event.implement.EscapeXmlReference

1:在velocity.properties中配置全局变量转义:


default.contentType=text/html; charset=UTF-8
input.encoding=UTF-8
output.encoding=UTF-8
eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeHtmlReference
eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeSqlReference
eventhandler.escape.html.match = /msg.*/
eventhandler.escape.sql.match = /sql.*/



2:在velocity.properties中配置局部变量转义:

default.contentType=text/html; charset=UTF-8
input.encoding=UTF-8
output.encoding=UTF-8
eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeHtmlReference
eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeSqlReference
eventhandler.escape.html.match = /_html_*/
eventhandler.escape.sql.match = /_sql_*/

前台数据显示时 要转义的数据变量名定义需遵循:


格式:_html_自定义名字

例如:_html_title、_html_userName等等


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics