首页 > 代码库 > java判断请求是否为ajax请求

java判断请求是否为ajax请求

/**
 * isAjaxRequest:判断请求是否为Ajax请求. <br/>
 * @param request 请求对象
 * @return boolean
 * @since JDK 1.6
 */
public boolean isAjaxRequest(HttpServletRequest request){
    String header = request.getHeader("X-Requested-With");
    boolean isAjax = "XMLHttpRequest".equals(header) ? true:false;
    return isAjax;
}