ASP中只有UrlEncode,沒有Urldecode問題的解決方法?
在ASP中傳遞參數(shù)時(shí)有一個(gè)很有用的系統(tǒng)函數(shù)Server.UrlEncode,可以將一些非字母數(shù)字的特殊符號(hào)轉(zhuǎn)換成標(biāo)準(zhǔn)URL編碼(其實(shí)就是16進(jìn)制ASC碼),這樣就解決了參數(shù)傳遞問題,然后我以為也提供了Server.UrlDecode,但使用后卻發(fā)現(xiàn)程序報(bào)錯(cuò),原來系統(tǒng)并沒有提供這個(gè)我想象中的解碼函數(shù)。怎幺辦,自己動(dòng)手吧。
UrlEncode的原理其實(shí)很簡(jiǎn)單,就是將特殊字符轉(zhuǎn)換成16進(jìn)制ASC碼值,那么譯碼函數(shù)就只要將16進(jìn)制ASC轉(zhuǎn)回對(duì)應(yīng)的字符就OK了。
Function URLDecode(enStr) 'URL解碼函數(shù) dim deStr dim c,i,v deStr="" for i=1 to len(enStr) c=Mid(enStr,i,1) if c="%" then v=eval("&h"+Mid(enStr,i+1,2)) if v<128 then deStr=deStr&chr(v) i=i+2 else if isvalidhex(mid(enstr,i,3)) then if isvalidhex(mid(enstr,i+3,3)) then v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2)) deStr=deStr&chr(v) i=i+5 else v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1))))) deStr=deStr&chr(v) i=i+3 end if else destr=destr&c end if end if else if c="+" then deStr=deStr&" " else deStr=deStr&c end if end if next URLDecode=deStr end function function isvalidhex(str) isvalidhex=true str=ucase(str) if len(str)<>3 then isvalidhex=false:exit function if left(str,1)<>"%" then isvalidhex=false:exit function c=mid(str,2,1) if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function c=mid(str,3,1) if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function end function
經(jīng)測(cè)試gb312格式的asp使用沒有問題。
相關(guān)文章
ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識(shí))
這篇文章是ASP基礎(chǔ)入門第二篇,第一篇展示了ASP動(dòng)態(tài)網(wǎng)站設(shè)計(jì)的一些最基本的方法,相信通過實(shí)踐各位對(duì) ASP 已經(jīng)有了最基本的了解,本文將進(jìn)一步介紹ASP動(dòng)態(tài)網(wǎng)站的一些基本技巧,需要的朋友可以參考下2015-10-10ASP動(dòng)態(tài)生成的javascript表單驗(yàn)證代碼
ASP動(dòng)態(tài)生成的javascript表單驗(yàn)證代碼...2006-11-11一個(gè)能對(duì)訪問者進(jìn)行編號(hào)、記錄訪問次數(shù)、IP、時(shí)間的統(tǒng)計(jì)制作實(shí)例
一個(gè)能對(duì)訪問者進(jìn)行編號(hào)、記錄訪問次數(shù)、IP、時(shí)間的統(tǒng)計(jì)制作實(shí)例...2006-12-12asp中記錄集對(duì)象的getrows和getstring用法分析
asp中記錄集對(duì)象的getrows和getstring用法分析,需要的朋友可以參考下2012-03-03ASP 使用jqGrid實(shí)現(xiàn)讀寫刪的代碼(json)
因?yàn)橛辛吮容^成型的CMS,一直沒有舍棄ASP,一直想用.net重寫一下,是后話了。2010-03-03asp中使用MSXML2.ServerXMLHTTP實(shí)現(xiàn)異步請(qǐng)求例子
這篇文章主要介紹了asp中使用MSXML2.ServerXMLHTTP實(shí)現(xiàn)異步請(qǐng)求例子,本文還給出了MSXML2.ServerXMLHTTP異步請(qǐng)求代碼編寫最常犯的錯(cuò)誤,需要的朋友可以參考下2014-08-08asp MYSQL出現(xiàn)問號(hào)亂碼的解決方法
用asp讀取MYSQL數(shù)據(jù)庫出現(xiàn)亂碼,讀取到的漢字都是????2008-08-08asp刪除mssql數(shù)據(jù)庫中沒有記錄的圖片代碼
asp刪除沒有記錄的圖片需要文件夾(存放圖片的文件夾)中的每個(gè)圖片和數(shù)據(jù)庫中的所有記錄進(jìn)行比較2009-08-08