对方提供的接口,调用后返回一个xml格式的长串,如下
Content-type:text/html
<?xml version='1.0' encoding='UTF-8'?><mailList><mail num="1">
<sender>[email protected]</sender>
<subject>转发: 转发: 欢迎使用邮件系统!</subject>
<date>2009-12-16 13:14</date>
<mailhref>http://211.121.219.180/cgi-bin/get_message2.cgi?sk=D0CSDIX4&fd=inbox&lang=gb&tf=shoujj/index2.htm&id=1260940456.12033.3.zgd_linux.localdomain&sort=0</mailhref>
</mail><mail num="2">
<sender>[email protected]</sender>
<subject>test</subject>
<date>2009-12-15 14:57</date>
<mailhref>http://211.121.219.180/cgi-bin/get_message2.cgi?sk=D0CSDIX4&fd=inbox&lang=gb&tf=shoujj/index2.htm&id=1260860228.21500.5.zgd_linux.localdomain&sort=0</mailhref>
</mail><totalnum>2</totalnum></mailList>现在要在页面上显示出<subject>的内容,<mailhref>链接,本人初学jsp,请大虾帮帮忙谢谢!
Content-type:text/html
<?xml version='1.0' encoding='UTF-8'?><mailList><mail num="1">
<sender>[email protected]</sender>
<subject>转发: 转发: 欢迎使用邮件系统!</subject>
<date>2009-12-16 13:14</date>
<mailhref>http://211.121.219.180/cgi-bin/get_message2.cgi?sk=D0CSDIX4&fd=inbox&lang=gb&tf=shoujj/index2.htm&id=1260940456.12033.3.zgd_linux.localdomain&sort=0</mailhref>
</mail><mail num="2">
<sender>[email protected]</sender>
<subject>test</subject>
<date>2009-12-15 14:57</date>
<mailhref>http://211.121.219.180/cgi-bin/get_message2.cgi?sk=D0CSDIX4&fd=inbox&lang=gb&tf=shoujj/index2.htm&id=1260860228.21500.5.zgd_linux.localdomain&sort=0</mailhref>
</mail><totalnum>2</totalnum></mailList>现在要在页面上显示出<subject>的内容,<mailhref>链接,本人初学jsp,请大虾帮帮忙谢谢!
解决方案 »
- webservice中ArrayOfstring类型应该怎么传入字符串信息
- eclipse 3.4从官网下载也是免费的吗?
- 为什么键盘不响应阿 操纵不了游戏
- Swing中的Jtable和JTree深入使用(求助)
- java 调用delphi写的dll问题,请知道的提出相关意见!!1
- 求教,关于一取整算法的思路?
- [高手来看]请问如何监听语音modem而获得来电显示号码?[高分求助]
- 如何获得ResultSet的记录数量啊
- HashMap中键对应的值可以重复吗
- 求大神指导Java小程序题异常部分变量问题
- 常量池是什么东东?String.intern()什么时候用?怎么用?
- java学习语音是不是还要下载什么东西???
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
file = new FileInputStream(path);
document = db.parse(file);
Element root = document.getDocumentElement();
NodeList list = root.getChildNodes()写一个解析xml方法,返回一个List,页面调用方法取list放到页面对应位置。
package com.isoftstone.Inheritance;import java.util.List;import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;public class ParseXml { /**
* @param args
*/
public static void main(String[] args) throws Exception{
SAXBuilder sb=new SAXBuilder();
Document doc=sb.build("e:/workspace/j2se/src/mail.xml"); //构造文档对象
Element root=doc.getRootElement(); //获取根元素
List list=root.getChildren("mail");//取名字为disk的所有元素
for(int i=0;i<list.size();i++){
Element element=(Element)list.get(i);
String sender=element.getChildText("sender");
String subject=element.getChildText("subject");//取disk子元素capacity的内容
String date=element.getChildText("date");
String mailhref=element.getChildText("mailhref");
System.out.println("mail:");
System.out.println("sender:"+sender);
System.out.println("subject:"+subject);
System.out.println("date:"+date);
System.out.println("mailhref:"+mailhref);
System.out.println("-----------------------------------");
}
}}
<?xml version='1.0' encoding='UTF-8'?>
<mailList>
<mail num="1">
<sender>[email protected] </sender>
<subject>转发: 转发: 欢迎使用邮件系统! </subject>
<date>2009-12-16 13:14 </date>
<mailhref>http://211.121.219.180/cgi-bin/get_message2.cgi?sk=D0CSDIX4&fd=inbox&lang=gb&tf=shoujj/index2.htm&id=1260940456.12033.3.zgd_linux.localdomain&sort=0 </mailhref>
</mail>
<mail num="2">
<sender>[email protected] </sender>
<subject>test </subject>
<date>2009-12-15 14:57 </date>
<mailhref>http://211.121.219.180/cgi-bin/get_message2.cgi?sk=D0CSDIX4&fd=inbox&lang=gb&tf=shoujj/index2.htm&id=1260860228.21500.5.zgd_linux.localdomain&sort=0 </mailhref>
</mail>
<totalnum>2 </totalnum>
</mailList>
req.open("POST", path+"/AjaxReadFileServlet");
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send("fileName="+fileName+"&lineCount="+lineCount);
req.onreadystatechange=function() {
if (req.readyState==4 && req.status==200) {
var rootNode=req.responseXML.documentElement;
var node = rootNode.getElementsByTagName("result");
if(node!=null){
try{
document.getElementById("logValue").value = node[0].firstChild.nodeValue;
}catch(e){
document.getElementById("logValue").value ="";
}
do something
}
}
}