1. 程式人生 > >Velocity模板引擎下 velocity.properties轉義(轉碼)配置

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等等