这段代码运行出来的为什么不一样?

weicl2005 2009-08-08 09:12:49

<%
Session.CodePage=65001

search=request.QueryString("search")
response.Write(search)%>
<br>
<%
response.Write(server.URLEncode(search))

%>
<br>
<%response.Write(server.URLEncode("去"))%>



运行结果:

%C8%A5
%E5%8E%BB


怎么弄,把search编出来是%E5%8E%BB的结果呢?
...全文
38 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wcwtitxu 2009-08-09
利用 JScript

<script language="JScript" runat="Server">
function escapeURI(str) { return encodeURIComponent(str); }
</script>
<%
Sub WriteLine(x)
Response.Write x
Response.Write "<br />"
End Sub

search = request.QueryString("search").Item

WriteLine search
WriteLine Server.URLEncode(search)
WriteLine escapeURI(search)
%>



改变 Session.CodePage

<%
Function escapeURI(str)
Dim oCodePage
oCodePage = Session.CodePage
Session.CodePage = 65001
escapeURI = Server.URLEncode(str)
Session.CodePage = oCodePage
End Function

Sub WriteLine(x)
Response.Write x
Response.Write "<br />"
End Sub

search = Request.QueryString("search").Item

WriteLine search
WriteLine Server.URLEncode(search)
WriteLine escapeURI(search)
%>


用 ADODB.Stream

<%
Function escapeURI(str)
Dim stm : Set stm = WScript.CreateObject("ADODB.Stream")
stm.Type = 2
stm.Open
stm.Charset = "UTF-8"
stm.WriteText str
stm.Position = 0
' stm.Charset = "ISO-8859-1"
stm.Type = 1
stm.Position = 3
escapeURI = stm.Read(-1)
stm.Close
Set stm = Nothing
Dim res, i, x
res = ""
For i = 1 To LenB(escapeURI)
x = AscB(MidB(escapeURI, i, 1))
If x < 128 Then
res = res & Escape(Chr(x))
ElseIf x > 15 Then
res = res & "%" & Hex(x)
Else
res = res & "%0" & Hex(x)
End If
Next
escapeURI = res
End Function

Sub WriteLine(x)
Response.Write x
Response.Write "<br />"
End Sub

' -----------------

search = Request.QueryString("search").Item

WriteLine search
WriteLine Server.URLEncode(search)
WriteLine escapeURI(search)
%>
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告