日期:2014-05-16  浏览次数:20438 次

js url浼犲€糺ava 椤甸潰url浼犲€间腑鏂囩紪鐮?amp;瑙g爜(杞?
js url浼犲€糺ava 椤甸潰url浼犲€间腑鏂囩紪鐮?amp;瑙g爜  鍒嗙被锛?java

鍦板潃鏍忎腑鍑虹幇姹夊瓧鐨勬儏鍐垫湁涓ょ锛屼竴绉嶆槸姹夊瓧鍑虹幇鍦║RL鐨勮矾寰勯儴鍒嗭紝涓€绉嶆槸姹夊瓧鍑虹幇鍦║RL鐨勪紶鍙傜殑閮ㄥ垎锛岀浜岀鎯呭喌鐨勬椂鍊欏繀椤婚噰鐢ㄧ紪鐮佸悗浼犲弬锛屾帴鍙楁椂瑙g爜鐨勬柟寮忓畬鎴愪紶鍙傘€俲s涓紪鐮佹湁escape(),encodeURI(),encodeURIComponent()涓変釜甯哥敤鐨勬柟娉曪紝escape()甯稿父鐢ㄥ湪鎻愪氦椤甸潰鍜屽鐞嗛〉闈㈢殑缂栫爜鏍煎紡鐩稿悓鐨勬儏鍐典笅锛堟瘮濡傚畠浠兘鏄疓B2312锛夛紝encodeURI()鍜宔ncodeURIComponent()鐨勭敤娉曞熀鏈浉鍚岋紝鍖哄埆鍦ㄤ簬encodeURIComponent()涔熷"?"绛夌壒娈婂瓧绗﹁繘琛岀紪鐮併€?
涓€寮€濮嬮亣鍒颁腑鏂囧弬鏁扮殑鏃跺€欙紝浣跨敤encodeURI()杩涜浜嗕竴閬嶇紪鐮侊紝浼犺繃鍘诲悗锛屽彂鐜拌В鐮佸嚭鐜伴棶棰橈紝浜庢槸鎯冲埌鍙兘鏄紪鐮佹柟娉曚娇鐢ㄩ敊璇紝浜庢槸浣跨敤escape()鏂规硶锛岃繖鏃跺彂鐜拌В鐮佹椂鎶涘嚭isHexDigit寮傚父銆傚€熷姪鐧惧害鎼滅储isHexDigit寮傚父锛?
鍙戠幇鍘熸潵锛屾槸escape()鏂规硶閫犳垚浜嗗紓甯革紝鍚屾椂浜嗚В浜嗘祻瑙堝櫒浼犻€掑湴鍧€鐨勪竴浜涘師鐞嗭紝鍦ㄦ祻瑙堝櫒鍦板潃鏍忛噷锛屾祻瑙堝櫒璁や负%鏄釜杞箟瀛楃锛屾祻瑙堝櫒浼氭妸%涓?涔嬮棿鐨勭紪鐮侊紝涓や綅涓や綅鍙栧嚭鍚庤繘琛岃В鐮?鐒跺悗鍐嶄紶閫掔粰澶勭悊椤甸潰锛?
鐒跺悗鐢卞鐞嗛〉闈㈣繘琛屽啀娆¤В鐮併€傜敱姝ゆ垜鎯冲埌涓€鐩翠娇鐢╡ncodeURI鏂规硶鏄纭殑锛屽彧鏄渶瑕佷娇鐢ㄤ袱娆ncodeURI鏂规硶锛屼緥濡俥ncodeURI(encodeURI("涓枃"));绗竴娆℃槸鎶婁腑鏂囩紪鐮佹垚%xy鐨勬牸寮忥紝
绗簩娆℃槸瀵?xy涓殑%杩涜缂栫爜,%缂栫爜鎴?25銆傛暣涓紶鍙傝繃绋嬪ぇ浣撳簲璇ユ槸锛氭彁浜ら〉闈娇鐢╡ncodeURI(encodeURI("涓枃"))缂栫爜,鎶婃渶鍚庣殑缂栫爜缁撴灉%25xy浼犻€掔粰澶勭悊椤甸潰鐨勮繃绋嬩腑锛屾祻瑙堝櫒鑾峰彇URL鍦板潃
锛堟敞鎰弌penModelDialog鏂规硶锛屾祻瑙堝櫒鑾峰彇涓嶅埌鍙傛暟缂栫爜锛夊悗瑙g爜鎴?xy锛岀劧鍚庢妸%xy浼犻€掔粰澶勭悊椤甸潰,澶勭悊椤甸潰浣跨敤URLDecoder.decode(request.getParameter("鍙傛暟鍚?),"UTF-8");瀹屾垚瑙g爜銆?
鎬荤粨锛?
1銆佹眽瀛楀嚭鐜板湪URL璺緞閮ㄥ垎鐨勬椂鍊欎笉闇€瑕佺紪鐮佽В鐮?
2銆佷娇鐢╡ncodeURI杩涜2娆$紪鐮?
3銆佸湪openModelDialog()鎵撳紑鐨勬ā寮忕獥浣撻噷娌″姙娉曠敤request.getParameter姝g‘鑾峰彇鍙傛暟;


瀹㈡埛绔拰鏈嶅姟鍣ㄥ湪浼犻€掓暟鎹椂鍙互鐢ㄨ繃婊ゅ櫒filter瑙e喅瀛楃缂栫爜闂锛屼絾filter鍙兘瑙e喅post鏂瑰紡鎻愪氦鐨勬暟鎹€傚浜巊et鏂瑰紡锛屽彲浠ヤ娇鐢ㄤ袱娆ncodeURI(encodeURI(鈥滀腑鏂団€?)骞跺湪鏈嶅姟鍣ㄤ腑浣跨敤URLDecoder.decode(鈥滀腑鏂団€? "UTF-8");

浠婂ぉ鐢ˋjax鏍¢獙鏁版嵁鏃朵篃閬囧埌杩欎釜闂锛屽敖绠¢〉闈€佺被鍜寃eb瀹瑰櫒閮界粺涓€浜嗗瓧绗︾紪鐮侊紝鎻愪氦鐨勬暟鎹緷鐒舵槸涔辩爜锛屾墍浠ュ氨閲囩敤浜?娆ncodeURI()缂栫爜鏂瑰紡锛屼贡鐮侀棶棰樺氨瑙e喅浜嗐€?
椤甸潰
var name=document.myForm.username.value;
var url="Ajax.do?method=check&name="+encodeURI(encodeURI(name));
xmlHttp.open("GET",url,true);
action涓?
String name = request.getParameter("name");
name = URLDecoder.decode(name, "UTF-8");

servlet杩斿洖鏁版嵁鏃讹紝灏嗗瓧绗︾紪鐮佽缃负utf-8灏卞彲浠ヤ簡锛屽洜涓篈jax鍙敮鎸乽tf-8
response.setContentType("text/xml;charset=utf-8");
PrintWriter out = response.getWriter();
out.print(result);