Today do spring MVC exception Unified processing this block, in the processing of the need to send the request to the zone is a traditional request or an AJAX request, online has ready-made code, I am the reference http://www.2cto.com/kf/201412/364393.html Inside of the practice. One of the
if
(!( request.getHeader(
"accept"
).indexOf(
"application/json"
) > -
1
|| ( request
.getHeader(
"X-Requested-With"
) !=
null
&& request
.getHeader(
"X-Requested-With"
).indexOf(
"XMLHttpRequest"
) > -
1
) ))
The segment code is the code that determines the type of request, but after repeated testing (tested with Goole, Firefox, 360 browser), the traditional request of the browser will also send the x-requested-with request header, So the above code does not really distinguish between a traditional request or an AJAX request. As to how to distinguish because of my limited ability has not yet come out (check the Internet, basically by the above method to distinguish)
About the X-requested-with request header to differentiate between an AJAX request or a normal request