gpt4 book ai didi

java - 如何获取本地主机:8080 from full URL

转载 作者:行者123 更新时间:2023-12-02 10:01:44 25 4
gpt4 key购买 nike

我的 URL 路径为 http://localhost:8080/welcome/this/is/a/test

我的Java行是

String domain = httpServletRequest.getServerName();

但这样我就得到了“localhost”。我也想要端口号我只想在字符串中获取“localhost:8080”。

最佳答案

一行代码即可实现

String hostName = request.getHeader("host");
System.out.println(" HostName : " + hostName);

关于java - 如何获取本地主机:8080 from full URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55570055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com