jsonå°±åmapçç¨æ³ä¸æ ·ï¼newä¸ä¸ªJSONObject json=new JSONObject();
json.put("username", username);
json.put("password",password);
ç¨httppclientè¿ä¸ªç±»ä¼ è¿å»ï¼post请æ±çè¯ä»£ç æ¯è¾å¤å°±ä¸åäºï¼æ说ä¸get请æ±æ¯å¦ä½ çweb项ç®ååæ¯ServletTest,并ä¸ä½ å¨é¡¹ç®éå个servletç±»ååå«testãé£ä¹æ²¡æç»å®ååçæ
åµä¸urlå°ååºè¯¥æ¯http ï¼ // +localhost:8080/ ServletTest/testï¼msg= ( json.toString)ã注ææ¬å¼§å
è¦å¨ä»£ç å®ç°ã ç¶åå¨æå¡å¨ç«¯æ¶çä¿¡æ¯å°±æ¯{âusernameâ:username , "password": password}æ ¼å¼çæ°æ®äºãå¨ä½ çtestç±»éé¢doGet(HttpRequest request , HttpResponse respone){
String msg=request.getParameter("msg");//å°±è½å¾å°{âusernameâ:username , "passworãããã
ç¶åJSONObject serverjson=new JSONObject(msg);
String name= serverjson.getString("username");
String password=serverjson.getString("password");
è¿æ ·å°±æ¯å°è£
åé解æçè¿ç¨
}.
温馨提示:内容为网友见解,仅供参考