这个很简单啊。
用java的URL类或者apache的HttpClient包,都可以直接发http请求,获得返回值
然后用dom4j,jdom之类的包解析xml,用xpath非常方便的。甚至可以不用java,用javascript里面的xmlhttp控件可以直接获得http请求的返回值。javascript里面也有dom解析的能力,这样都不用经过后台处理了。直接显示出来
用java的URL类或者apache的HttpClient包,都可以直接发http请求,获得返回值
然后用dom4j,jdom之类的包解析xml,用xpath非常方便的。甚至可以不用java,用javascript里面的xmlhttp控件可以直接获得http请求的返回值。javascript里面也有dom解析的能力,这样都不用经过后台处理了。直接显示出来
解决方案 »
- 做报表查询的数据时间统计的问题!~都来看看
- 当输入页面中含有日期如2009-10-10时,如果Form中对于的字段为Date类型,则会出现“argument type mismatch”错误
- 有了解jetspeed的么,谁知道国内有哪些网站是基于jetspeed构建的,谢谢
- 过滤器无法拦截的烦心事儿,请大侠帮满解决
- 高手门,帮忙看看代码哪里错了,折磨我好几天!!!
- 给Java web版的朋友们散分~
- 利用jasperreport+jfreechart如何实现图形报表与数据报表的同时显示?
- 禁止使用Struts2类型转换
- 在jsp 中如何调用oracle存储过程
- Java 获取数据库的数据导入到excel模板中,模板有多个表头,表头的位置不固定是动态的,同时一个excel有多个sheet
- 关于JavaBean在JSP页面调用的问题(初学)
- 利用jsp技术如何把数据库中的数据导出到word或者excle中?
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的文档看看吧。很简单的
可以设置那个程序里面的sUrl变量为http://www.csdn.net?id=111&sds=111
就id、sds就是你要传的参数
post方式就用httpclient的吧
网上找不到,谢谢了
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里实现,大哥帮忙到底了,非常感谢啊
把服务器端的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();
}