web服务端访问xml资源文件的路径问题

来源:互联网 发布:oral电动牙刷知乎 编辑:程序博客网 时间:2024/06/03 08:37

     现在我需要访问web服务端的xml文件,解析xml文件,并将内容返回回来。首要的一个问题是怎么访问xml的路径,我现在假设web项目结构如下所示:

使用httpUtils的getXML方法访问这个person.xml文件,则路径的写法如下:

String path=http://192.168.0.28:8080/web/person.xml;

    其中,IP地址为服务端的IP地址,web为部署在tomcat服务器端的名字,后面的xml资源文件即为需要访问的文件。

    另外附上httpUtils源码


    

public class HttpUtils {    public HttpUtils() {    }    public static InputStream getXML(String path){        InputStream inputStream=null;        try{            URL url=new URL(path);            if(url!=null){                HttpURLConnection connection=(HttpURLConnection)url.openConnection();                connection.setConnectTimeout(3000);                connection.setDoInput(true);                connection.setRequestMethod("GET");                int code=connection.getResponseCode();                if(code==200){                    inputStream=connection.getInputStream();                }            }        }catch(Exception e){               e.printStackTrace();        }        return inputStream;    }}