Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In spring mvc, headers = "x-requested-with:XMLHttpRequest" in request mapping not working?

I have two methods, one is supposed to handle login request issued by JS, another takes care of login page.

 @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() {......}

However, all the login requests seems to go to the getLoginPage method whether it has "x-requested-with:XMLHttpRequest" header or not. I doubled checked http headers, it contains correct head. So it seems Spring just ignores the login method.

I've been struggling with this for a while, any advice would be greatly appreciated, thanks!

like image 283
Bobo Avatar asked Jan 20 '23 15:01

Bobo


1 Answers

headers uses = as a delimiter:

@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD},     
    headers = "x-requested-with=XMLHttpRequest") 
like image 90
axtavt Avatar answered Jan 29 '23 10:01

axtavt