1. 文件的编码确保是UFT-8:
workspace : eclipse -> window -> Preferences -> General -> Workspace -> Text file encoding 改成 UTF-8
项目是继承workspace的编码,也可以单独设置:右键项目,Properties -> Resource-> Text file encoding 改成 UTF-8
2. jsp 加上
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<Connector URIEncoding="UTF-8"4. 过滤器filter,在web.xml:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
<url-pattern>*.htm</url-pattern>
</filter-mapping>5.mysql的编码:
在my.ini文件里加上一句:
[mysql]
default-character-set=utf8可以执行下列命令查询:
SHOW VARIABLES LIKE 'char%';
本文详细介绍了如何在Eclipse环境中及Web应用中彻底解决中文乱码问题,包括配置Eclipse工作区编码、JSP页面编码、HTML元信息、Tomcat服务器URI编码、数据库字符集以及使用Spring框架的CharacterEncodingFilter。
993

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



