在Spring mvc中,headers ="x-requested-with:XMLHttpRequest"请求映射不起作用?

Bob*_*obo 3 ajax spring-mvc

我有两种方法,一种是应该处理JS发出的登录请求,另一种是处理登录页面.

 @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD},
    headers = "x-requested-with:XMLHttpRequest")
    public @ResponseBody String login() {...}


 @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD})
    public String getLoginPage() {......}
Run Code Online (Sandbox Code Playgroud)

但是,所有登录请求似乎都转到getLoginPage方法,无论它是否具有"x-requested-with:XMLHttpRequest"标头.我加倍检查http标头,它包含正确的头.所以看来Spring只是忽略了登录方法.

我一直在努力解决这个问题,任何建议都将不胜感激,谢谢!

axt*_*avt 8

headers使用=作为分隔符:

@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD},     
    headers = "x-requested-with=XMLHttpRequest") 
Run Code Online (Sandbox Code Playgroud)