r*****r 发帖数: 397 | 1 想表达如果相对地址以 \ 开头,like \data.html
if (addr.startsWith("\\")) // url like /data.html
{
String baseurl2 = baseurl.getHost();
URL relativeURL = new URL(baseurl2+addr);
}
else //url like data.htm, relative url
{
relativeURL = new URL(baseurl+addr);
}
when there is a relateive url named /data.html, it didn't go to if section,
but go to else section, made a result like
htt://www....//data.html
error in connecting.
What's wrong with the expression?SHould be sth wrong with "\\" here, how to
use escape | F****n 发帖数: 3271 | 2 1. I never saw URL like \data.html
always use "/" instead of "\"
2. Look at URI.resolve, it does the right things.
【在 r*****r 的大作中提到】 : 想表达如果相对地址以 \ 开头,like \data.html : if (addr.startsWith("\\")) // url like /data.html : { : String baseurl2 = baseurl.getHost(); : URL relativeURL = new URL(baseurl2+addr); : } : else //url like data.htm, relative url : { : relativeURL = new URL(baseurl+addr); : }
|
|