1.下载 jdom
http://www.jdom.org/dist/binary/jdom-2.0.6.zip
2.把解压出来的 jar 文件放 tomcat lib 目录下
tomcat/lib
3.jsp 页面代码如下
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.net.,java.io." %>
<%@page import="org.xml.sax.InputSource,org.xml.sax.XMLReader,org.jdom.,org.jdom.input.,org.jdom.output.,org.jdom2.input.,org.jdom2.output.,org.jdom2." %>
<%@ page import="java.util.List,java.util.Iterator" %>
<%
request.setCharacterEncoding("utf-8");
BufferedReader in = request.getReader();
InputSource source = new InputSource(in);
SAXBuilder sb = new SAXBuilder();
try {
Document doc = sb.build(source);
Element root = doc.getRootElement();
String retcode=root.getChildTextTrim("retcode");
List jiedian = root.getChildren();
Element et = null;
for(int i=0;i<jiedian.size();i++){
et = (Element) jiedian.get(i);
}
//out.println(et.toString());
String state="";
state=et.getChildTextTrim("state");
} catch(Exception ex) {
//ex.printStackTrace();
out.println(ex.toString());
}
%>