如何以编程方式将 href 设置为另一个网站?
how to set href to outter website programatically?
我正在以编程方式生成 html 页面。
我有这个 src 的 href
"https:/www.w.com/editor/?lon=-72.382769&lat=41.324657"
然而,当我像这样生成 html 时:
private Span getEditorSpan(CompleteRoutingResponseShort response) {
Span span4 = new Span();
for (int i = 0; i < response.alternatives.size(); i++) {
String editorUrl = editorUrlGenerator
.generateUrl(response.alternatives.get(i).response.results);
A a3 = new A();
a3.appendText("alt " + i);
a3.setTitle(response.alternatives.get(i).alternative_regression_id);
a3.setHref(editorUrl);
span4.appendChild(ImmutableList.of(a3, new Span().appendText("   ")));
}
return span4;
}
结果是一个 href,指向:
"http://localhost:63342/https:/www.w.com/editor/?lon=-72.382769&lat=41.324657"
这是结果 html:
<span><a title="358_0" href="https:/www.w.com/editor/?lon=-71.18612999999999&lat=42.21286&zoom=4&segments=63385498,76487105,22543109,22503638,22527613,76599462,76599461,76599460">alt 0</a><span> </span></span>
如何使 url 直接在我的本地主机域之外?
这是我的 url 建造者:
UriBuilder builder = UriBuilder
.fromPath(Constants.EDITOR_BASE_URL)
.scheme("https");
builder.queryParam("lon", firstPath.x)
.queryParam("lat", firstPath.y)
.queryParam("zoom", 4)
.queryParam("segments", segmentsInUrl);
return builder.build().toString();
您 URL 中设置的协议是 https:/
而不是 'https://'。这会导致应用程序认为它是一个亲戚 URL。解决这个问题,之后它不应该在域名http://localhost:63342
之前。
解决方案是更改我的 UriBuilder:
我已经更改了我的 UriBuilder
来自这个:
UriBuilder builder = UriBuilder
.fromPath("www.w.com/editor/";)
.scheme("https");
builder.queryParam("lon", firstPath.x)
.queryParam("lat", firstPath.y)
.queryParam("zoom", 4)
.queryParam("segments", segmentsInUrl);
return builder.build().toString();
对此:
Path firstPath = results.get(0).path;
UriBuilder builder = UriBuilder
.fromUri("https://www.w.com/editor/")
.queryParam("lon", firstPath.x)
.queryParam("lat", firstPath.y)
.queryParam("zoom", 4)
.queryParam("segments", segmentsInUrl);
return builder.build().toString();
}
我正在以编程方式生成 html 页面。
我有这个 src 的 href
"https:/www.w.com/editor/?lon=-72.382769&lat=41.324657"
然而,当我像这样生成 html 时:
private Span getEditorSpan(CompleteRoutingResponseShort response) {
Span span4 = new Span();
for (int i = 0; i < response.alternatives.size(); i++) {
String editorUrl = editorUrlGenerator
.generateUrl(response.alternatives.get(i).response.results);
A a3 = new A();
a3.appendText("alt " + i);
a3.setTitle(response.alternatives.get(i).alternative_regression_id);
a3.setHref(editorUrl);
span4.appendChild(ImmutableList.of(a3, new Span().appendText("   ")));
}
return span4;
}
结果是一个 href,指向:
"http://localhost:63342/https:/www.w.com/editor/?lon=-72.382769&lat=41.324657"
这是结果 html:
<span><a title="358_0" href="https:/www.w.com/editor/?lon=-71.18612999999999&lat=42.21286&zoom=4&segments=63385498,76487105,22543109,22503638,22527613,76599462,76599461,76599460">alt 0</a><span> </span></span>
如何使 url 直接在我的本地主机域之外?
这是我的 url 建造者:
UriBuilder builder = UriBuilder
.fromPath(Constants.EDITOR_BASE_URL)
.scheme("https");
builder.queryParam("lon", firstPath.x)
.queryParam("lat", firstPath.y)
.queryParam("zoom", 4)
.queryParam("segments", segmentsInUrl);
return builder.build().toString();
您 URL 中设置的协议是 https:/
而不是 'https://'。这会导致应用程序认为它是一个亲戚 URL。解决这个问题,之后它不应该在域名http://localhost:63342
之前。
解决方案是更改我的 UriBuilder:
我已经更改了我的 UriBuilder
来自这个:
UriBuilder builder = UriBuilder
.fromPath("www.w.com/editor/";)
.scheme("https");
builder.queryParam("lon", firstPath.x)
.queryParam("lat", firstPath.y)
.queryParam("zoom", 4)
.queryParam("segments", segmentsInUrl);
return builder.build().toString();
对此:
Path firstPath = results.get(0).path;
UriBuilder builder = UriBuilder
.fromUri("https://www.w.com/editor/")
.queryParam("lon", firstPath.x)
.queryParam("lat", firstPath.y)
.queryParam("zoom", 4)
.queryParam("segments", segmentsInUrl);
return builder.build().toString();
}