一、確保jsp頁面中<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>和<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">編碼為UTF-8;
二、post方式
配置字符過濾器


































配置web.xml


















三、get方法
1、配置tomcat中server.xml
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" disableUploadTimeout="true" URIEncoding="UTF-8"/>
2、在要傳遞參數的時候進行轉碼(如不轉碼奇數中文字符最后一個字符亂碼)
(1)JSP傳值方式:
跳轉頁:
<a href=info.jsp?info="<%= java.net.URLEncoder.encode("中文漢字","GBK") %>">跳轉</a>
接收頁
<%
String info_str = new String(request.getParameter("info"),"ISO8859-1");
out.print(info_str); //輸出接收值
%>
(2)JS傳值方式:
先用encodeURI()進行編碼
var p = "你好嗎?";
var url = "aaa.jsp?param=" + encodeURI(p);
然后在服務器端要解碼
<%
String param = request.getParameter("p");
param = new String(param.getBytes("ISO-8859-1"),"UTF-8");
%>
四、ajax亂碼
在要傳遞中文參數的js中轉碼:encodeURIComponent(“×××”)