聽
聽
杩欑瘒鏂囩珷鏄涓婁竴绡囨枃绔犵殑琛ュ厖
聽
鏌ョ湅鍘熸枃绔爃ttp://licg1234.iteye.com/blog/867632
聽
1.娴忚鍣ㄨВ鏋愭湇鍔$椤甸潰鐨勭紪鐮佹柟寮忎笉鍐嶈銆?
聽
2.娴忚鍣ㄧ鍙戦€佹暟鎹殑缂栫爜鏍煎紡锛?
聽聽 聽1.javascript涓?
聽聽 聽 url缂栫爜瑙g爜encodeURI涓巈ncodeURIComponent 鍑芥暟閮芥槸鍩轰簬utf-8锛堥粯璁ゅ鐞嗭紝澶у璁颁綇灏卞彲浠ヤ簡锛?杩欎袱涓嚱鏁扮殑鍖哄埆鎴戜釜浜虹悊瑙f潵璇村氨鏄痚ncodeURI鏄鐞唘rl鐨?锛岃€宔ncodeURIComponent鏄鐞唘rl涓瘡涓弬鏁扮殑銆?
聽
聽
聽
浠g爜濡備笅:
var uri="my test.asp?name=stale&car=saab";
document.write(encodeURI(uri));
涓婇潰鐨勮緭鍑哄涓嬶細
my%20test.asp?name=st%C3%A5le&car=saab
encodeURIComponent
浠g爜濡備笅:
var uri="http://jb51.net/my test.asp?name=stale&car=saab";
document.write(encodeURIComponent(uri));
涓婇潰鐨勮緭鍑哄涓嬶細
http%3A%2F%2Fjb51.net%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
聽聽聽
聽
聽
聽聽 聽2.闄や簡url鍦板潃鏍忎腑鏁版嵁鐨勭紪鐮佹牸寮忎笌鐜鏈夊叧绯诲,椤甸潰鍐呯殑鏁版嵁閮介噰鐢ㄤ簡褰撳墠椤甸潰鏈韩鐨勭紪鐮佹牸寮忥紙鐜杩樻槸璇达紝<meta聽http-equiv="Content-Type"聽content="text/html;聽charset=GBK">杩欓噷瑙勫畾鐨勬牸寮忥級銆偮犅狅級
聽聽渚嬪锛?
聽聽聽<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
<script type="text/javascript">
var url="http://servlet.do?a=浣犲ソ&b=浣犲ソ";
window.location.href=url;
</script>
</head>
<body>
</body>
</html>
聽
聽聽杩欎釜椤甸潰涓殑var url=銆傘€傘€傘€傘€?聽url鐨勭紪鐮佹牸寮忓氨鏄疓BK銆?
聽聽form琛ㄥ崟涓殑鏁版嵁鍚屾牱鐨勩€傚皬灏忔€荤粨锛氶〉闈㈠唴閮ㄦ墍鏈夌殑鏁版嵁缂栫爜鏍煎紡閮芥槸Content-Type 鍐冲畾鐨勩€?
聽
聽聽3.椤甸潰form post鎻愪氦鐨勬暟鎹鐞嗗涓嬶細
聽
聽聽 聽 聽
application/x-www-form-urlencoded | 鍦ㄥ彂閫佸墠缂栫爜鎵€鏈夊瓧绗︼紙榛樿锛?/td> |
multipart/form-data | 涓嶅瀛楃缂栫爜銆? 鍦ㄤ娇鐢ㄥ寘鍚枃浠朵笂浼犳帶浠剁殑琛ㄥ崟鏃讹紝蹇呴』浣跨敤璇ュ€笺€? |
text/plain | 绌烘牸杞崲涓?"+" 鍔犲彿锛屼絾涓嶅鐗规畩瀛楃缂栫爜銆?/td> |
聽聽 聽 杩欎釜鏄痟ttp form瑙勫畾
聽
聽
聽聽4.ajax get鎻愪氦涔熷氨鏄痷rl鎻愪氦鍚屾櫘閫氱殑url鎻愪氦涓€鏍枫€傝繖閲屼富瑕佽鐨勬槸post鎻愪氦銆俛jax post鎻愪氦娌℃湁閬靛惊涓婇潰鐨勮〃鏍笺€?
聽聽瀹冨鎻愪氦鐨勬暟鎹兘娌℃湁杩涜缂栫爜銆?
聽
聽
聽
聽聽5.閫氳繃鍒嗘瀽涓婇潰鍑犵偣锛屽ぇ瀹堕兘娴忚鍣ㄧ鎻愪氦鍒板悗鍙扮殑鏁版嵁鐨勭紪鐮佹牸寮忛兘搴旇鏈変簡澶ф鐨勪簡瑙c€?
聽
聽
3.涓嬮潰璇存湇鍔″櫒瑙f瀽鏁版嵁
聽聽聽request.getParameter("")鎺ユ敹鏁版嵁,棣栧厛杩涜涓€娆¤В鐮侊紙鎵€鏈夋湇鍔″櫒閮芥槸濡傛锛屽彲鑳絟ttp鍗忚瑕佹眰锛壜?
聽聽 鏃㈢劧鏄В鐮佹€诲緱鏈変釜瑙g爜鐨勬柟寮忓惂锛歵omcat榛樿瑙g爜鏂瑰紡閮芥槸iso-8859-1锛屽埆鐨勬湇鍔″櫒澶у鑷繁鐪嬩笅銆?
聽
聽聽 聽1.瀵瑰簲get鏂瑰紡鐨勮姹傦紝tomcat杩涜浜嗕竴娆¢粯璁ょ殑iso-8859-1瑙g爜锛堟€庝箞鏇存敼tomcatget榛樿瑙g爜鏂瑰紡锛屽ぇ瀹惰嚜宸变笂缃戞悳绱笅宸达級,杩欎釜鏃跺€欏ぇ瀹跺氨鍙互鏍规嵁瀹㈡埛绔彂閫佽繃鏉ョ殑缂栫爜绫诲瀷杩涜鎿嶄綔浜嗐€?
聽聽 聽2.瀵瑰簲post鏂瑰紡鐨勮姹傦紝
聽聽聽杩欓噷charset鐨勫€艰幏寰楁柟寮忎负濡備笅涓ゆ锛?
聽
聽聽 聽 聽 聽 聽 聽 聽 锛?锛塺equest.getCharacterEncoding("utf-8"),濡傛灉鑾峰緱鐨勭紪鐮佹牸寮忎笉涓虹┖锛屽ソ鐨勶紝瑙g爜鐢ㄨ繖绉嶆牸寮忥紙涓嶈蛋绗簩姝ヤ簡锛夊鏋滆幏寰楃殑缂栫爜鏍煎紡涓虹┖,濂界殑鍙兘杩涜绗簩姝ヤ簡
聽聽 聽 聽 聽 聽 聽 聽 (2) 聽 涓庢湇鍔″櫒榛樿post瑙g爜鏍煎紡 聽 聽渚嬪锛歵omcat瑙g爜榛樿涓篿so-8859-1.
聽聽 聽 3.鐫€閲嶈鏄庝竴鐐癸細
聽聽 聽 聽 聽 聽 聽涓句釜渚嬪瓙锛氭祻瑙堝櫒椤甸潰GBK鏍煎紡缂栫爜 閲囩敤form 聽post 聽application/x-www-form-urlencoded 鏂瑰紡鎻愪氦鏁版嵁锛岋紝瑕佸彂閫佹暟鎹亣璁句负a 锛岄偅涔堝彂閫佸墠鍏堝a缂栫爜涓篵锛?
聽聽 聽 聽 聽 聽 tomcat鏈嶅姟鍣ㄦ帴鍙楀埌鏁版嵁b鍚庯紝鍋囪request.getCharacterEncoding("utf-8")缂栫爜鏍煎紡涓虹┖銆傞偅涔堟湇鍔″b杩涜url瑙g爜(iso-8859-1.鏍煎紡銆? 鍋囪涓?B锛屾鏃跺緱鍒扮殑鏁版嵁鏃朵粈涔堟牱瀛愬憿锛?
聽聽鏄鏁版嵁a鐨刬so-8859-1缂栫爜鏍煎紡 聽鍋囪涓篶 锛堝嵆锛歝=new String(B.getBytes(""GBK""),"iso-8859-1")锛夛紝閭d箞鎴戜滑鎬庝箞鏍峰緱鍒癮鐨勫師濮嬫暟鎹憿锛屽皢c杩樺師涓篴 聽 鍗筹細new String(B.getBytes("iso-8859-1"),"GBK");
聽
聽
聽聽4.鐫€閲嶈鏄?
聽聽 聽 url瑙g爜杩囩▼涓嶄細瀵瑰師濮嬫暟鎹湁浠讳綍鎹熷潖锛屽叿浣撹繕瑕佸ぇ瀹惰嚜宸卞璇曢獙涓嬩簡銆?
聽聽 聽聽/**
* @param args
*/
public static void main(String[] args) {
try {
String username="http://servlet.do?a=浣犲ソ&b=浣犲ソ";
String dcodeuriusername=URLDecoder.decode(username, "UTF-8");
System.out.println(dcodeuriusername);
//result: http://servlet.do?a=浣犲ソ&b=浣犲ソ
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
聽聽鎬荤粨锛?
聽聽 聽 聽 聽 聽 聽 1.涓昏鍏虫敞鐐瑰湪浜庯細娴忚鍣ㄧ鍙戦€佹暟鎹殑鍏冪礌鍘熷缂栫爜绫诲瀷锛屽彂閫佺殑鏁版嵁鏄惁杩涜浜嗙紪鐮?
聽聽 聽 聽 聽 聽 聽 聽 澶у鍙渶瑕佽浣忛〉闈orm post鎻愪氦鐨勬暟鎹?
锛坅pplication/x-www-form-urlencoded ----杩涜浜唘rl缂栫爜澶勭悊, text/plain----绌烘牸杞崲涓?"+" 鍔犲彿锛?
浣嗕笉瀵圭壒娈婂瓧绗︾紪鐮侊級銆?
鍗冲彧鏈夎繖涓ょform post鎻愪氦鐨勬暟鎹被鍨?杩涜浜?
缂栫爜澶勭悊鍏朵腑application/x-www-form-urlencoded涓烘瀹楃殑url缂栫爜灏卞彲浠ヤ簡
聽聽 聽 聽 聽 聽 2.鏈嶅姟鍣ㄧ鎺ュ埌鏁版嵁鍚庨兘杩涜浜嗕竴娆rl瑙g爜澶勭悊锛岃嚦浜庢€庝箞瑙g爜灏变笌鐩稿簲鐨?web鏈嶅姟鍣ㄤ笌get post鏂瑰紡鏈夊叧浜嗐€?
聽聽 聽 聽 聽 聽 聽鏈嶅姟绔笉閲囩敤榛樿url瑙g爜鍙湁涓€绉嶆儏鍐碉細
聽聽 聽 聽 聽 聽 聽 post鎻愪氦骞朵笖request.getCharacterEncoding("utf-8")鑾峰緱鐨勭紪鐮佹牸寮忎笉涓虹┖
聽