如何获取一个url的返回值,并显示在网页中?
最好用静态页面的方法,比如javascript能做到吗请注意:我要的是url的返回值,不是url本身啊!
比如访问http://a.test.com/test.asp?action=get这个地址返回字符串hello
我要用得到的是hello,而不是所访问的url

解决方案 »

  1.   

    URL url = null;
            try {
                url = new URL("http://a.test.com/test.asp?action=get");
            } catch (MalformedURLException ex1) {
            }
            HttpURLConnection connection = null;
            try {
                connection = (HttpURLConnection) url.openConnection();
            } catch (IOException ex2) {
                ex2.printStackTrace();
                return;
            }        BufferedReader urlIn = null;
            try {
                urlIn = new BufferedReader(new InputStreamReader(connection.
                        getInputStream(), "gb2312"));
            } catch (IOException ex3) {
                ex3.printStackTrace();
                return;
            }
            String urlLine = "";
            StringBuffer line = new StringBuffer();
            try {            while ((urlLine = urlIn.readLine()) != null) {
                    line.append(urlLine.trim());
                }
            } catch (IOException ex4) {
                ex4.printStackTrace();
                return;
            }
            try {
                urlIn.close();
            } catch (IOException ex5) {
                ex5.printStackTrace();
                return;
            }
            urlLine = line.toString();