如何以编程方式将href设置为outter网站?

时间:2015-06-22 07:01:25

标签: html css href

我以编程方式生成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("&nbsp&nbsp&nbsp")));
    }
    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&amp;lat=42.21286&amp;zoom=4&amp;segments=63385498,76487105,22543109,22503638,22527613,76599462,76599461,76599460">alt 0</a><span>&nbsp;&nbsp;&nbsp;</span></span>

如何将网址直接放在我的localhost域之外?

这是我的网址构建器:

    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();

2 个答案:

答案 0 :(得分:2)

您网址中设置的协议为https:/,而不是&#39; https://&#39;。这会导致应用程序认为它是相对URL。修复此问题,之后不应该预先添加域名http://localhost:63342

答案 1 :(得分:0)

解决方案是改变我的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();
}