http://yonge812.iteye.com/blog/1010290 Velocity中文乱码问题需要注意一下几点:

1、eclipse默认编码方式

2、页面的编码方式

3、volocity模板的编码方式

第一步:

选择工程右键->Properties->Resource  查看默认的编码方式
第二步:
Java代码  
  1. <%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
Java代码  
  1. 或者
Java代码  
  1. <filter>
  2. <filter-name>CharacterEncodingFilter</filter-name>
  3. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  4. <init-param>
  5. <param-name>encoding</param-name>
  6. <param-value>gbk</param-value>
  7. </init-param>
  8. </filter>
  9. <filter-mapping>
  10. <filter-name>CharacterEncodingFilter</filter-name>
  11. <url-pattern>/*</url-pattern>
  12. </filter-mapping>

第三步:

Java代码  
  1. <!-- 配置velocity引擎 -->
  2. <bean id="velocityConfigurer"
  3. class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  4. <!-- 模板路径 -->
  5. <property name="resourceLoaderPath" value="WEB-INF/velocity/" />
  6. <property name= "velocityProperties">
  7. <props>
  8. <prop key= "input.encoding">gbk</prop>
  9. <prop key= "output.encoding">gbk</prop>
  10. </props>
  11. </property>
  12. </bean>
  13. <!-- 配置视图解析器 -->
  14. <bean id="viewResolver"
  15. class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
  16. <property name="suffix" value=".vm" /><!-- 上面已经指定了模板路径,这里只需定义后缀 -->
  17. <property name="contentType" value="text/html;charset=gbk"></property> <!-- 设置编码格式 -->
  18. </bean>

或者

在properties属性文件中写入:
Java代码  
  1. input.encoding=gbk
  2. output.encoding =gbk

检查上述几个地方配置是否一致即可。

Velocity中文乱码问题解决方法的更多相关文章

  1. WingIDE中文乱码问题解决方法

    WingIDE中文乱码问题解决方法 安装完WingIDE后,首次运行python脚本时,若脚本中含有UTF-8中文,在Debug I/O输出框中,全部变成了乱码. 这时其实我们设置下WingIDE的编 ...

  2. 【转】asp.net Cookie值中文乱码问题解决方法

    来源:脚本之家.百度空间.网易博客 http://www.jb51.net/article/34055.htm http://hi.baidu.com/honfei http://tianminqia ...

  3. soapUI参数中文乱码问题解决方法 (groovy脚本中文乱码)

    soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...

  4. LoadRunner中文乱码问题解决方法

    LoadRunner中文乱码问题解决方法 前段时间在录制,增强,整合LoadRunner脚本,期间两次遇到了中文乱码问题.在此记录一下中文乱码问题的解决办法. 一.录制回放中文乱码 我录制登陆的脚本, ...

  5. python3 库pandas写入csv格式文件出现中文乱码问题解决方法

    python3 库pandas写入csv格式文件出现中文乱码问题解决方法 解决方案: 问题是使用pandas的DataFrame的to_csv方法实现csv文件输出,但是遇到中文乱码问题,已验证的正确 ...

  6. soapUI参数中文乱码问题解决方法&soap UI工具进行web接口测试

    soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...

  7. tomcat启动控制台中文乱码问题解决方法

    tomcat启动控制台中文乱码问题解决方法,修改tomcat安装路径/conf/logging.properties文件 java.util.logging.ConsoleHandler.encodi ...

  8. tomcat项目中文乱码问题解决方法

    在部署tomcat项目时经常会遇到中文乱码问题,解决的方法可参考以下步骤. 1.更改Tomcat安装目录下的conf\server.xml,指定浏览器的编码格式为"utf-8"格式 ...

  9. JSP中文乱码问题解决方法小结

    在使用JSP的过程中,最使人头疼的一个问题就是中文乱码问题,以下是我在软件开发中遇到的乱 码问题以及解决方法. 1.JSP页面乱码 这种乱码的原因是应为没有在页面里指定使用的字符集编码,解决方法:只要 ...

随机推荐

  1. The number of steps(概率dp)

    Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...

  2. Codeforces Round #424 B. Keyboard Layouts(字符串,匹配,map)

    #include <stdio.h> #include <string.h> ][]; ]; ]; int main(){ scanf(]); scanf(]); scanf( ...

  3. codeforces Round #440 C Maximum splitting【数学/素数与合数/思维/贪心】

    C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. D - Interesting Calculator 【数值型BFS+优先队列】

    There is an interesting calculator. It has 3 rows of buttons. Row 1: button 0, 1, 2, 3, ..., 9. Pres ...

  5. HDU 多校1.8

  6. numeric column can contains null

  7. Reference resources

    CentOS7 (精简操作指令) http://www.centoscn.com/CentOS/help/2016/0429/7147.html

  8. [P2396] yyy loves Maths VII

    Link: P2396 传送门 Solution: 一眼能看出$O(n*2^n)$的状压$dp$ 但此题是个卡常题,$n=23/24$的时候就别想过了 这题算是提供了一种对状压$dp$的优化思路吧 原 ...

  9. 【对询问分块】【主席树】bzoj2683 简单题

    对操作序列分块,每S次暴力重建主席树. 当S=sqrt(n*log(n))时,复杂度为O(m*sqrt(n*log(n))). 在线的. #include<cstdio> #include ...

  10. python3-开发面试题(python)6.22基础篇(1)

    1.为什么学习Python? 1.语言排行榜 2.语言本身简洁,优美,功能超级强大的 3.跨平台 4.非常火爆的社区 5.用的公司的多 2.通过什么途径学习的Python? 某宝2.8就搞定了,跟着视 ...