java类(客户端)接收servlet返回值
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> //测试类如下 import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; public class ClientTest { //定义servlet路径,MyServlet是工程名字,自己可以修改 private static String path="http://localhost:8080/MyServlet/QueryServlet"; public static void main(String[] args) throws Exception { URL url =new URL(path); //接收servlet返会值,是字节 InputStream is=url.openStream(); //由于is是字节,所以我们要把它转换为String类型,否则遇到中文会出现乱码 BufferedReader reader=new BufferedReader(new InputStreamReader(is)); StringBuffer sb=new