Spring MVC: How to get the remaining path after the controller path?
- by Willis Blackburn
I've spent over an hour trying to find the answer to this question, which seems like it should reflect a common use case, but I can't figure it out!
Basically I am writing a file-serving controller using Spring MVC. The URLs are of the format http://www.bighost.com/serve/the/path/to/the/file.jpg, in which the part after "/serve" is the path to the requested file, which may have an arbitrary number of path segments. I have a controller like this:
@Controller
class ServerController {
@RequestMapping(value = "/serve/???")
public void serve(???) {
}
}
What I am trying to figure out is: What do I use in place of "???" to make this work?
I have two theories about how this should work.
The first theory is that I could replace the first "???" in the RequestMapping with a path variable placeholder that has some special syntax meaning "capture to the end of the path." If a regular placeholder looks like "{path}" then maybe I could use "{path:**}" or "{path:/}" or something like that. Then I could use a @PathVariable annotation to refer to the path variable in the second "???".
The other theory is that I could replace the first "???" with "**" (match anything) and that Spring would give me an API to obtain the remainder of the path (the part matching the "**"). But I can't find such an API.
Thanks for any help you can provide!