我已經工作的servlet需要轉換爲Spring MVC控制器來訪問彈簧bean等。爲什麼在普通servlet request.getPathInfo()
返回不是null
,但在Spring Controller中我得到空值?我知道我可以使用@PathVariable
,但不知道爲什麼這種方法的結果是差異?Spring MVC控制器 - getPathInfo()爲空
@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...
}
}
你打的網址是什麼? –
URL:'http:// localhost:8080/myApp/test/hello'。 'req.getPathInfo()'shuld return'/ hello' – marioosh