且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从url字符串中删除get参数的***方法是什么?

更新时间:2023-02-09 14:07:04

可能不是最有效的方式,但更安全类型:

Probably not the most efficient way, but more type safe :

private String getUrlWithoutParameters(String url) throws URISyntaxException {
    URI uri = new URI(url);
    return new URI(uri.getScheme(),
                   uri.getAuthority(),
                   uri.getPath(),
                   null, // Ignore the query part of the input url
                   uri.getFragment()).toString();
}