How can I skip the execution in doFilter
for only an Ajax request?
As of now I am passing parameter called isAjax
. Is there a "standard" way to do this?
How can I stop execution in filter in this scenario? Will adding return
statement be a proper approach?
Most browsers add a special request-header when sending AJAX requests. You can easily check that using this snippet:
public static boolean isAjaxRequest(HttpServletRequest request) {
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
}
Note, however, that this is no perfect guarantee, as this header starts with X-
, it is not a standard header and browsers / client code may decide not to send it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With