asp网页地址栏传过来的参数有许多种,如数字,英文,汉字等;不同的页面编码,传递汉字的方法也不一样。下面学步园小编来讲解下ASP读取地址栏传递过来的参数有哪些方法?
ASP读取地址栏传递过来的参数有哪些方法
1。支持参数纯汉字aspbc。asp?a=深山老熊
2。支持参数gb2312Urlencode编码:aspbc。asp?a=%C9%EE%C9%BD%C0%CF%D0%DC
3。支持参数UTF-8Urlencode编码:aspbc。asp?a=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
代码如下:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
<%
OptionExplicit
ConstYXCMS_CHARSET="UTF-8"
ConstYXCMS_CODEPAGE=65001
Response。CharSet="UTF-8"
Session。CodePage=65001
'测试URL
'aspbc。asp?n1=深山老熊&n2=%C9%EE%C9%BD%C0%CF%D0%DC&n3=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
'深山老熊
'GBK:%C9%EE%C9%BD%C0%CF%D0%DC
'UTF-8:%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
DimURI,key
SetURI=newCls_URI
'输出所有参数测试
ForEachkeyInURI。QueryString
Response。Write"
"
Next
'取单个值
'URI。Get("名称")
'——————————————————————————————
'ASPUTF-8编码下通吃GBKUTF-8编码
'作者:深山老熊QQ:81090
'————————————————————————————
ClassCls_URI
Privateo_item,o_regx
Privateurl_query
PrivateSubClass_Initialize
Seto_item=CreateObject("Scripting。Dictionary")
o_item。CompareMode=1
Seto_regx=NewRegexp
o_regx。Pattern="^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$"
Session。CodePage=936
url_query=Request。ServerVariables("QUERY_STRING")
Session。CodePage=65001
ASP读取地址栏传递过来的参数有哪些方法
'根据QUERY_STRING字符串,生成模拟QueryString值
Dimi,a,b,c,n,v
a=Split(url_query,"&"):c=UBound(a)
Fori=0Toc
b=Split(a(i),"=",2)
n=Trim(b(0)&"")
IfUBound(b)<1Then v="" Else v=b(1) IfInStr(v,"%")>0Thenv=URLDecode(v)
EndIf
Ifn<>""Then
o_item(n)=v
EndIf
Next
Seto_regx=Nothing
EndSub
PrivateSubClass_Terminate
Seto_item=Nothing
EndSub
'模拟Request。QueryString
PublicFunctionQueryString()
SetQueryString=o_item
EndFunction
'模拟Request。QueryString(n)
PublicFunction[GET](n)
Ifo_item。Exists(n)Then
[GET]=o_item。Item(n)
Else
[GET]=""
EndIf
EndFunction
'编码格式化
PrivateFunctionURLDecode(ByVals)
Dimsm,cs,r,o_regex
IfTrim(s&"")=""Then
URLDecode=s:ExitFunction
EndIf
s=unescape(s)
Ifo_regx。Test(s)Then
cs="UTF-8"
Else
cs="GBK"
EndIf
Setsm=CreateObject("Adodb。Stream")
Withsm
。Type=2
。Mode=3
。Open
。CharSet="ISO-8859-1"
。WriteTexts
。Position=0
。CharSet=cs
URLDecode=。ReadText(-1)
。Close
EndWith
Setsm=Nothing
EndFunction
EndClass
%>
以上就是关于“ASP读取地址栏传递过来的参数有哪些方法”的内容,希望对大家有用。更多资讯请关注学步园。学步园,您学习IT技术的优质平台!