一、確保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、在要傳遞參數(shù)的時(shí)候進(jìn)行轉(zhuǎn)碼(如不轉(zhuǎn)碼奇數(shù)中文字符最后一個(gè)字符亂碼)
(1)JSP傳值方式:跳轉(zhuǎn)頁:<a href=info.jsp?info="<%= java.net.URLEncoder.encode("中文漢字","GBK") %>">跳轉(zhuǎn)</a>接收頁<% String info_str = new String(request.getParameter("info"),"ISO8859-1"); out.print(info_str); //輸出接收值%>(2)JS傳值方式:先用encodeURI()進(jìn)行編碼 var p = "你好嗎?";var url = "aaa.jsp?param=" + encodeURI(p);然后在服務(wù)器端要解碼<%String param = request.getParameter("p");param = new String(param.getBytes("ISO-8859-1"),"UTF-8");%>四、ajax亂碼
在要傳遞中文參數(shù)的js中轉(zhuǎn)碼:encodeURIComponent(“×××”)