我如何从网址
中读取xml文件并在jsp页面中准确显示整个xml主体?
我在jsp中尝试了jdom
<%@ page import="org.jdom2.Document" %>
<%@ page import="org.jdom2.Element" %>
<%@ page import="org.jdom2.input.*" %>
<%
StringBuilder responseBuilder = new StringBuilder();
try {
// Create a URLConnection object for a URL
URL url = new URL( "http://eampl.ecom/text.xml" );
URLConnection conn = url.openConnection();
HttpURLConnection httpConn;
httpConn = (HttpURLConnection)conn;
BufferedReader rd = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line;
while ((line = rd.readLine()) != null)
{
responseBuilder.append(line + '\n');
}
out.println(responseBuilder.toString());
}
catch(Exception e){
out.println(e);
}
%>
但它唯一的返回值。我需要有价值的完整xml体。任何人都可以指导我吗?