Reputation: 28566
I have worked servlet that need to convert to Spring MVC controller to have access spring beans etc. Why in normal servlet request.getPathInfo()
return not null
, but in Spring Controller i get null value ? I know i can use @PathVariable
, but wonder why the results of this method is the difference?
@RequestMapping(value = {"/test", "/test/*"})
public void test(HttpServletRequest req, HttpServletResponse res) {
log.info(req.getPathInfo() == null); // true!
if (req.getMethod().equalsIgnoreCase("get")) {
// analogue to doGet...
} else {
// analogue to doPost...
}
}
Upvotes: 9
Views: 6172
Reputation: 7722
I think the solution is in the javadoc of getPathInfo()
The extra path information follows the servlet path but precedes the query string and will start with a "/" character.
In case of Spring the servlet path is the full path hence if you call getServletPath() it will always return the full URI and getPathInfo() will return nothing.
Upvotes: 14