1.web.xml文件裏配置
<filter>
<filter-name>CharacterEncodingFilter</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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.數據庫配置文件 url加上useUnicode=true&characterEncoding=utf8 html
3.tomcat的server.xml添加URIEnCoding=utf-8java
4.servelt處理請求處添加request.setCharacterEncoding("utf-8")
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("UTF-8")web
5.html jsp ftl 等頁面設置
html頁面spring
在頁面的<head>標籤內添加<meta>標籤,內容以下數據庫
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> (建議這個)tomcat
或者
<meta charset="utf-8">app
jsp頁面jsp
在jsp頁面的頂部加上如下代碼,重點是charset=UTF-8和pageEncoding="UTF-8"ui
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>url
同時在<head>標籤下添加<meta>標籤,代碼以下
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6.建表時指定utf-8格式