2
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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.