乱码情况及解决方法:
1、页面到服务器:
《1》<%@ page contentType="text/html; charset=UTF-8" language="java"%>
< script type="text/javascript">
《2》js:encodeURI(encodeURI(str));
Controller:URLDecoder.decode(str,"UTF-8")
《3》str = new String("str".getByte("iso-8859-1"),"uft-8")
2、服务器到页面:response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
2、服务器到数据库之间
确保服务器编码及数据库编码一致
服务器端:<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
数据库端:
比如Mysql:
jdbc:mysql://localhost:3306/test?characterEcoding=UTF-8&name=root&password=abc123
Done.