您的位置:首页 > 编程语言 > Java开发

spring下使用velocity的中文乱码问题

2007-05-29 18:18 603 查看

1 为了简单,所有文档都用utf-8编码。

2 在xxxx-servlet.xml中配置使用velocity的view的返回编码为utf-8

<bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix"><value>.vm</value></property>
<property name="contentType"><value>text/html;charset=UTF-8</value></property>
</bean>

3 在xxx-servlet.xml中配置velocity引擎使用的编码

<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>/pc/vm/</value>
</property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">utf-8</prop>
<prop key="output.encoding">utf-8</prop>
</props>
</property>
</bean>
有人说可以配置一个velocity.properties将input.encoding的信息配置。没试过,似乎可行。

这样基本上保证无乱码了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: