asp 獲取url函數(shù)小結(jié)
更新時間:2009年11月06日 00:20:35 作者:
asp 獲取url函數(shù)小結(jié),需要的朋友可以參考下。
方法一:簡單,得不到參數(shù),只有一個虛擬路徑
GetUrl =request("url")
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:shiyan.asp
<%
dim changdu,url,ends,wurl
changdu=len(request.ServerVariables("URL"))
url=instrrev(request.ServerVariables("URL"),"/")
url=url+1
ends=changdu+1-url
wurl=mid(request.ServerVariables("URL"),url,ends)
%>
方法二:得到整個URL,得到參數(shù)
'得到當(dāng)前頁面的地址
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法三:得到虛擬路徑,得到參數(shù)
Private Function GetUrl()
Dim ScriptAddress,M_ItemUrl,M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得當(dāng)前地址
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If M_item = "page_num" Then Exit for '此處的作用就是過濾掉Page_num這個頁次的參數(shù)(該參數(shù)是在page_turn.asp中自行設(shè)置的,根據(jù)個人設(shè)定而變),否則每次翻頁都會疊加這個參數(shù),雖然不影響功能,但總歸不太好吧~~
If InStr(page,M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&""))
else
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
Else
ScriptAddress = ScriptAddress & "?"
end if
GetUrl = ScriptAddress & M_ItemUrl
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法四:只獲取參數(shù)部分字符串
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
geturl=mid(geturl,instr(geturl,"?")+1)
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:dfsdfsf=dsfsdfd&aa=dddd
復(fù)制代碼 代碼如下:
GetUrl =request("url")
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:shiyan.asp
復(fù)制代碼 代碼如下:
<%
dim changdu,url,ends,wurl
changdu=len(request.ServerVariables("URL"))
url=instrrev(request.ServerVariables("URL"),"/")
url=url+1
ends=changdu+1-url
wurl=mid(request.ServerVariables("URL"),url,ends)
%>
方法二:得到整個URL,得到參數(shù)
復(fù)制代碼 代碼如下:
'得到當(dāng)前頁面的地址
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法三:得到虛擬路徑,得到參數(shù)
復(fù)制代碼 代碼如下:
Private Function GetUrl()
Dim ScriptAddress,M_ItemUrl,M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得當(dāng)前地址
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If M_item = "page_num" Then Exit for '此處的作用就是過濾掉Page_num這個頁次的參數(shù)(該參數(shù)是在page_turn.asp中自行設(shè)置的,根據(jù)個人設(shè)定而變),否則每次翻頁都會疊加這個參數(shù),雖然不影響功能,但總歸不太好吧~~
If InStr(page,M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&""))
else
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
Else
ScriptAddress = ScriptAddress & "?"
end if
GetUrl = ScriptAddress & M_ItemUrl
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法四:只獲取參數(shù)部分字符串
復(fù)制代碼 代碼如下:
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
geturl=mid(geturl,instr(geturl,"?")+1)
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
獲取為:dfsdfsf=dsfsdfd&aa=dddd
相關(guān)文章
服務(wù)器XMLHTTP(Server XMLHTTP in ASP)基礎(chǔ)知識
幾年很流行 Ajax,而 Ajax 的本質(zhì)就是 XMLHttpRequest,是客戶端 XMLHttpRequest 對象的使用。2010-08-08
將ACCESS轉(zhuǎn)化成SQL2000要注意的問題
很多朋友想用SQL2000數(shù)據(jù)庫的編程方法,但是卻又苦于自己是學(xué)ACCESS的,對SQL只是一點點的了解而已,這里我給大家提供以下參考---將ACCESS轉(zhuǎn)化成SQL2000的方法和注意事項2007-03-03

