我已经工作的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