package com.xmomen.module.core.web;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;


public class WebCommonUtils {

    // 判断请求是否为JSON格式
    public static boolean isJSON(ServletRequest request){
        // 判断请求头中是否包含"X-Requested-With"字段，且值为"XMLHttpRequest"
        if("XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With"))
                // 判断请求头中是否包含"Content-Type"字段，且值为"application/json"
                || "application/json".equalsIgnoreCase(request.getContentType())){
            return true;
        }
        return false;
    }
}
