最近接触velocity,发现vm模板会出现中文乱码情况。velocity.properties 文件也配置了
input.encoding=UTF-8
output.encoding=UTF-8
但没效果,依旧乱码。struts.xml里也配置了
<constant name="struts.i18n.encording" value="UTF-8"></constant>然而,并没什么卵用,其实只需在vm文件里加入<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />即可,如下:<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登录</title>
</head>
本文介绍了在使用Velocity模板引擎时遇到的中文乱码问题及其解决方案。即使在velocity.properties文件中设置了正确的编码格式UTF-8,仍然可能出现乱码。文章提供了一个简单有效的方法:在VM文件头部添加<meta>标签来指定字符集。
408

被折叠的 条评论
为什么被折叠?



