java替換url的域名和埠
阿新 • • 發佈:2019-01-25
public static String replaceDomainAndPort(String domain,String port,String url){
String url_bak = "";
if(url.indexOf("//") != -1 ){
String[] splitTemp = url.split("//");
url_bak = splitTemp[0]+"//";
if(port != null){
url_bak = url_bak + domain+":"+port;
}else{
url_bak = url_bak + domain;
}
if(splitTemp.length >=1 && splitTemp[1].indexOf("/") != -1){
String[] urlTemp2 = splitTemp[1].split("/");
if(urlTemp2.length > 1){
for(int i = 1;i < urlTemp2.length; i++){
url_bak = url_bak +"/"+urlTemp2[i];
}
}
System.out.println("url_bak:"+url_bak);
}else{
System.out.println("url_bak:"+url_bak);
}
}
return url_bak;
}
String url_bak = "";
if(url.indexOf("//") != -1 ){
String[] splitTemp = url.split("//");
url_bak = splitTemp[0]+"//";
if(port != null){
url_bak = url_bak + domain+":"+port;
}else{
url_bak = url_bak + domain;
}
if(splitTemp.length >=1 && splitTemp[1].indexOf("/") != -1){
String[] urlTemp2 = splitTemp[1].split("/");
if(urlTemp2.length > 1){
for(int i = 1;i < urlTemp2.length; i++){
url_bak = url_bak +"/"+urlTemp2[i];
}
}
System.out.println("url_bak:"+url_bak);
}else{
System.out.println("url_bak:"+url_bak);
}
}
return url_bak;
}