从jsp读取xml表单URL

时间:2013-07-17 19:50:44

标签: jsp

我如何从网址

中读取xml文件

示例:http://eampl.ecom/text.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体。任何人都可以指导我吗?

0 个答案:

没有答案