4
Map<String, String> pathVariables = (Map<String, String>) request
                .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

Using above code, I was able to get the pathVariables but...
How can i get these parameters in order, as this is unordered map so it will not provide me ordered keys according to the url? for eg: i have http://localhost:8080/url/123/234/xyz/123 which should map to http://localhost:8080/url/{id}/{deptId}/{code}/{empId}. Now how can i know that first 123 maps to id or empId ???

I want this url path parameter in exact order so that i could map it for my usecase. Any help would be appreciated.

Gourav Kumar
  • 205
  • 1
  • 7

1 Answers1

1

Actually, you can't do that easily using just servlet api. Frameworks are doing that for you, like spring web-mvc and dropwizard. You have to implement your servlet or servlets the way they can handle uris with specific structure and then extract desired path variables. That's pretty complex. I would suggest using some web framework for that or at least some library that will help you.

Good luck.

bpawlowski
  • 1,025
  • 2
  • 11
  • 22
  • Can you tell me any library which can help in this. any library either spring-web-mvc or dropwizard which you are telling. actually the above code though which i am getting the path variables not in order through, its spring-web specific, but i need same order. – Gourav Kumar Aug 01 '22 at 11:36