这个很简单啊。
用java的URL类或者apache的HttpClient包,都可以直接发http请求,获得返回值
然后用dom4j,jdom之类的包解析xml,用xpath非常方便的。甚至可以不用java,用javascript里面的xmlhttp控件可以直接获得http请求的返回值。javascript里面也有dom解析的能力,这样都不用经过后台处理了。直接显示出来

解决方案 »

  1.   

    public class UrlTest {
        public static void main(String args[]) {
            String sUrl = "http://www.csdn.net";  //假设这个网址提供一个xml文件
            BufferedReader reader = null;
            try {
                URL su = new URL(sUrl);            URLConnection uc = su.openConnection();
                StringBuffer sb = new StringBuffer();
                Reader r = new InputStreamReader(su.openStream());
                reader = new BufferedReader(r);
                String s = null;
                do {
                    s = reader.readLine();
                    if(s!=null){
                        sb.append(s).append("\r\n");
                    }
                } while (s != null);
                System.out.println(sb.toString());  //打印出xml
                
                //TODO 解析xml文件,这里略过
                
            } catch (IOException e1) {
                e1.printStackTrace();
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }解析xml自己找dom4j的文档看看吧。很简单的
      

  2.   

    "用java的URL类或者apache的HttpClient包,都可以直接发http请求,获得返回值"请问下怎么发送http请求啊
      

  3.   

    一般是Http的get请求
    可以设置那个程序里面的sUrl变量为http://www.csdn.net?id=111&sds=111
    就id、sds就是你要传的参数
    post方式就用httpclient的吧
      

  4.   

    是在java bean里还是jsp里?能给我具体代码不啊?
    网上找不到,谢谢了
      

  5.   

    <script language=javascript> 
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
    xmlDoc.async="false"; 
    xmlDoc.load("http://****.com/scripts/****.asp?subcode=C22"); 
    nodes = xmlDoc.documentElement.childNodes; 
    var text = xmlDoc.selectSingleNode("//last").text 
    document.write(text); 
    </script>网上好多都是在javascript里的,但我需要是在java或jsp里实现,大哥帮忙到底了,非常感谢啊
      

  6.   

    http://www-128.ibm.com/developerworks/cn/views/xml/tutorials.jsp
      

  7.   

    我是这样实现的,
    把服务器端的xml转换为输入流,然后用dom4j解析.
    ----------------------------------
    //获得输入流
        protected InputStream getURLInputStream()
        {
            InputStream inStream=null;
            try
            {
            URL   url = new URL("http://****.com/scripts/****.asp?subcode=C22");
         
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent", "rssReader/1.0");//这儿随便改一下,我原来是写一个rss解析器
            connection.setRequestProperty("Accept-Encoding", "gzip, *");
            connection.setDoInput(true);
            connection.setDoOutput(true);
            HttpURLConnection httpConn = (HttpURLConnection)connection;
            BufferedInputStream bins=new BufferedInputStream(httpConn.getInputStream(),1024);
            DataInputStream din = new DataInputStream(bins);
            inStream=din;
            } catch (MalformedURLException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return inStream;
        }
    ---------------------//下面是用dom4j写的一个rss解析方法,你可以参考
       protected void rssParser()
        {
            try
            {
                SAXReader reader = new SAXReader(); 
                Document doc= reader.read(getURLInputStream());
                Element root = doc.getRootElement(); 
             Element channel=root.element("channel");
            Element foo; 
            RSS rss=null;
             for (Iterator i = channel.elementIterator("item"); i.hasNext();) 
             {
                 foo = (Element)i.next(); 
                 rss=new RSS();
                 rss.setTitle(foo.elementText("title")); 
                 rss.setLink(foo.elementText("link"));
                 rss.setAuthor(foo.elementText("author"));
                 rss.setDescription(foo.elementText("description"));
                 rss.setPubDate(foo.elementText("pubDate"));
                 rss.setClassid(rssChannel.getClassid());
                 rss.setChannelid(rssChannel.getChannelid());
                 rssList.add(rss);
             }
            // in.close();
         } catch (DocumentException e2)
         {
             // TODO Auto-generated catch block
             e2.printStackTrace();
         }