Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Ok, this is a similar approach to what I've done so far. But I'm searching for a way to do this without actually using the HttpServletRequest object. This is because I'm using several helper classes / methods and I don't want to pass the request object every time. Commented Sep 29, 2009 at 7:41
  • Ok, I know what you mean and added the info you need to access the current request without passing it around. Commented Sep 29, 2009 at 8:06
  • Thanks for the reminder about the listener. I'm still new to Spring (and Java web development in general). I'm now using your code in combination with Spring Security's UrlUtils. Works like a charm. Commented Sep 29, 2009 at 8:41
  • In my case it gives the related view path instead of browse url. Any idea about this? Commented Aug 5, 2018 at 16:04
  • Without using HttpServletRequest... example in Spring Boot controller methods we don't get this as a parameter... then the other answer of the static call looks good ServletUriComponentsBuilder.fromCurrentRequest().toUriString() Commented Oct 16, 2020 at 6:37