您的位置:首页 > 其它

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

2017-09-19 17:02 344 查看
     现在我需要访问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;
}
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: