1.getParameter是用来获取URL中的参数的
HttpServletRequest request
String action_flag = request.getParameter("action_flag");
if (action_flag.equals("person")) {
jsonString = JsonTools.createJsonString("person",
service.getPerson());
}
URL:http://192.168.2.1:8080/jsonp/servlet/JsonA?action_flag=person
2.将inputStream装换为string
private static String changeInputStream(InputStream inputStream) {
// TODO Auto-generated method stub
String jsonString="";
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
int len=0;
byte[] data=new byte[1024];
try {
while((len=inputStream.read(data))!=-1){
outputStream.write(data, 0, len);
}
jsonString=new String(outputStream.toByteArray());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonString;
}