This question already has answers here:
How to obtain the last path segment of an uri
                                
                                    (11个答案)
                                
                        
                                4年前关闭。
            
                    

我想获得引荐来源网址的最后一部分。如何获得此信息的最佳方法是什么?


String referrer = request.getHeader("referer");


目前,这就是获取引荐来源网址的方式。这给了我整个URL,但是我只想要URL的一部分。


例如:请求的URL:http://localhost:8080/TEST/ABC.html
如果这是引荐来源网址,我只需要ABC.html

感谢您的协助,如果我的问题有任何误解,请告诉我。

最佳答案

这将为您提供XYZ.html:

String url = "http://localhost:8080/TEST/XYZ.html";
url = url.substring(url.lastIndexOf("/") + 1, url.length());

07-24 20:00