ASP同一站點(diǎn)下gb2312和utf-8頁(yè)面?zhèn)鬟f參數(shù)亂碼的終極解決方法
更新時(shí)間:2010年12月22日 22:38:36 作者:
要解決ASP同一站點(diǎn)下gb2312和utf-8頁(yè)面?zhèn)鬟f參數(shù)亂碼問(wèn)題,只需嚴(yán)格做到以下4點(diǎn)即可。
①.頁(yè)面文件使用正確的編碼,gb2312使用ANSI,utf-8使用utf-8;
②.ASP代碼中設(shè)置正確的CODEPAGE,gb2312使用936,utf-8使用65001;
③.HTML代碼中設(shè)置正確的charset,gb2312使用gb2312,utf-8使用utf-8;
④.將傳遞的參數(shù)值使用js的escape函數(shù)進(jìn)行編碼;
示例代碼
t1.asp(ANSI編碼):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Session.CodePage=936%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Page(gb2312)-jb51.net</title>
</head>
<body>
<script type="text/javascript">
document.write("<a href='t2.asp?keyword=" + escape("木子屋") + "'>木子屋</a>");
</script>
<br/>
<%
Response.Write(Request.QueryString("keyword"))
%>
</body>
</html>
t2.asp(utf-8編碼):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page(utf-8)-jb51.net</title>
</head>
<body>
<script type="text/javascript">
document.write("<a href='t1.asp?keyword=" + escape("木子屋") + "'>木子屋</a>");
</script>
<br/>
<%
Response.Write(Request.QueryString("keyword"))
%>
</body>
</html>
②.ASP代碼中設(shè)置正確的CODEPAGE,gb2312使用936,utf-8使用65001;
③.HTML代碼中設(shè)置正確的charset,gb2312使用gb2312,utf-8使用utf-8;
④.將傳遞的參數(shù)值使用js的escape函數(shù)進(jìn)行編碼;
示例代碼
t1.asp(ANSI編碼):
復(fù)制代碼 代碼如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Session.CodePage=936%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Page(gb2312)-jb51.net</title>
</head>
<body>
<script type="text/javascript">
document.write("<a href='t2.asp?keyword=" + escape("木子屋") + "'>木子屋</a>");
</script>
<br/>
<%
Response.Write(Request.QueryString("keyword"))
%>
</body>
</html>
t2.asp(utf-8編碼):
復(fù)制代碼 代碼如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page(utf-8)-jb51.net</title>
</head>
<body>
<script type="text/javascript">
document.write("<a href='t1.asp?keyword=" + escape("木子屋") + "'>木子屋</a>");
</script>
<br/>
<%
Response.Write(Request.QueryString("keyword"))
%>
</body>
</html>
相關(guān)文章
asp實(shí)現(xiàn)本周的一周時(shí)間列表的代碼
原理也相對(duì)簡(jiǎn)單,就是利用date函數(shù)獲取日期,然后通過(guò)固定的字符串?dāng)?shù)組進(jìn)行替換。2009-02-02ASP常見(jiàn)錯(cuò)誤詳解及解決方案小結(jié) 推薦
ASP是非常簡(jiǎn)單的,以至于許多的開(kāi)發(fā)者不會(huì)去思考錯(cuò)誤處理。錯(cuò)誤處理能夠讓你的應(yīng)用程序更加合理。我看到過(guò)很多個(gè)用ASP編寫(xiě)的商業(yè)網(wǎng)站,大多數(shù)都忽略了錯(cuò)誤處理。 錯(cuò)誤的類(lèi)型。2011-01-01ASP基礎(chǔ)入門(mén)第六篇(ASP內(nèi)建對(duì)象Request)
從本篇開(kāi)始作者從 ASP 內(nèi)建對(duì)象著手,為大家詳細(xì)剖析 ASP 的六個(gè)內(nèi)建對(duì)象和各種組件的特性和方法,需要的朋友可以參考下2015-10-10ASP中保留小數(shù)點(diǎn)后兩位數(shù)的方法(使用FormatNumber)
這篇文章主要介紹了ASP中保留小數(shù)點(diǎn)后兩位數(shù)的方法,使用FormatNumber函數(shù)實(shí)現(xiàn),需要的朋友可以參考下2014-06-06利用ASP實(shí)現(xiàn)在線生成電話圖片效果腳本附演示
利用ASP實(shí)現(xiàn)在線生成電話圖片效果腳本附演示...2007-11-11用ASP實(shí)現(xiàn)寫(xiě)IIS日志的代碼
用ASP實(shí)現(xiàn)寫(xiě)IIS日志的代碼...2007-11-11asp 使用正則表達(dá)式替換word中的標(biāo)簽,轉(zhuǎn)為純文本
asp里使用正則表達(dá)式清除后臺(tái)編輯器里復(fù)制粘貼內(nèi)容的word格式,將其轉(zhuǎn)換成純文本2010-04-04