Java HttpServletRequest get URL in browsers URL bar

后端 未结 7 679
旧巷少年郎
旧巷少年郎 2020-11-27 14:03

So I\'m trying to grab the current URL of the page using Java\'s request object. I\'ve been using request.getRequestURI() to preform this, but I noticed that when a java cla

7条回答
  •  抹茶落季
    2020-11-27 14:52

    To get the HTTP requested path without know the state of the internal flow of the request, use this method:

    public String getUri(HttpServletRequest request) {
        String r = (String) request.getAttribute("javax.servlet.forward.request_uri");
        return r == null ? request.getRequestURI() : r;
    }
    

提交回复
热议问题