如何删除url java中的参数

q3qa4bjr  于 2021-07-13  发布在  Java
关注(0)|答案(2)|浏览(322)

我运行项目时有一个url。
http://localhost:8084/blog1\u 1/title?uname=55%22
我想从这个url中删除查询字符串,如下所示:
http://localhost:8084/blog1\u 1/标题
你能告诉我怎么做吗?

0dxa2lsx

0dxa2lsx1#

String url="http://localhost:8084/blog1_1/title?uname=55%22";
String onlyUrl=url.substring(0,url.lastIndexOf("?")); //this has the URL
sg24os4d

sg24os4d2#

假设 url 是java字符串:

String newURL = url.substring(0, url.indexOf("?"));

我应该做这个把戏。。。

相关问题