(一)
Apache 通过 ajp 与Tomcat连接
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
<Connector port="8889" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
在http连接方式,及AJP方式中,都需要加上URIEncoding="UTF-8"
如果只在HTTP连接中加上,那么直接访问8888端口是正常,通过Apache访问则一样是乱码
(二)没效果
服务器端:
======
修改httpd.conf (在Redhat中放置的位置为/etc/httpd/conf/)
查找:
AddDefaultCharset ISO-8859-1
改成:
#AddDefaultCharset ISO-8859-1
AddDefaultCharset off
这种方式关掉了服务器的默认语言的发送,这样仅凭html文件头中设置的语言来决定网页语言。
有人直接用
AddDefaultCharset GB2312
但是不建议这样做。
重新启动Apache,
/etc/init.d/httpd restart
客户端:
=====
在中文网页请中依情况在标签中添加:
GB2312 (简体中文):
<META http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
BIG5(繁体中文):
<META http-equiv=”Content-Type” content=”text/html; charset=big5″ />
UTF-8: (注意是UTF-8,而不是UTF8)
<META http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
如果还是不正常,请清空浏览器的Cache试试。
(三) 未实现不通过js
百度的js
=========
var w = window, d = document, n = navigator, k = d.f.wd, a = d.getElementById(
"nv").getElementsByTagName("a"), isIE = n.userAgent.indexOf("MSIE") != -1;
if (!isIE || window.opera) {
d.getElementById("sh").style.display = "none"
}
for ( var i = 0; i < a.length; i++) {
a[i].onclick = function() {
if (k.value.length > 0) {
var e = this, b = e.href, c = encodeURIComponent(k.value);
if (b.indexOf("q=") != -1) {
e.href = b.replace(/q=[^&$]*/, "q=" + c)
} else {
this.href += "?q=" + c
}
}
}
}
(function() {
if (/q=([^&]+)/.test(location.search)) {
k.value = decodeURIComponent(RegExp.$1)
}
})();
========