我如何从 url 读取 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 正文。有人可以指导我吗?