English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java method for replacing the domain name and port of the URL

Example as follows:

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;
} 

This article on replacing the domain and port of java url is all the content that the editor shares with everyone. I hope it can give everyone a reference and also hope everyone will support the Shouting Tutorial.

Guess you like