protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String urlss = "http://127.0.0.1:8080/test/ShopServlet";
StringBuilder responseBuilder = null;
BufferedReader reader = null;
OutputStreamWriter wr = null;
URL url;
try {
url = new URL(urlss);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setConnectTimeout(1000 * 5);
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write("cctv");//写入数据
wr.flush();
// Get the response
reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
responseBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
responseBuilder.append(line + "\n");
}
wr.close();
reader.close();
response.getWriter().print(responseBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("---");
StringBuffer json=new StringBuffer();
byte[] bytes=new byte[1024];
while(request.getInputStream().read(bytes)>0){
json.append(new String(bytes,"utf-8"));
}
System.out.println("---");
System.out.println(json.toString().trim());
response.getWriter().print("a"+json.toString().trim()+"b");
}