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...
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With