It determines whether the request is ajax

It determines whether the request is ajax 
reproduced: HTTP: //www.cnblogs.com/tony-jingzhou/archive/2012/07/30/2615612.html 

X-requested-request header with 
the request from the server-side determination request Ajax (Asynchronous) or traditional request (synchronous): 
        two kinds of different requests in the header of the request, Ajax asynchronous request more parameters than a conventional header synchronization request 
  
        1 , a conventional synchronization request parameter
     accept text / html, application / xhtml + xml, application / xml; Q = 0.9, * / *; Q = 0.8 
    Accept-charset GB2312, UTF-. 8; Q = 0.7, *; Q = 0.7 
    Accept-encoding the gzip, the deflate 
    Accept-Language ZH-CN, ZH; Q = 0.5 
    Cache-Control Age-0 = max 
    Connection Keep-Alive 
    Cookie = 1A3BED3F593EA9747C9FDA16D309AF6B the JSESSIONID 
    Host 192.168.101.72:8080 
    Keep-Alive 300 
    Referer XXX
    user-agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 (.NET CLR 3.5.30729)
 
       2、Ajax 异步请求方式
    accept  */*
    accept-language  zh-cn
    referer  xxx
    x-requested-with  XMLHttpRequest  //表明是AJax异步
    content-type  application/x-www-form-urlencoded,text/javascript
    accept-encoding  gzip, deflate
    user-agent  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; QQDownload 598; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; CIBA; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1)
    Host   192.168.101.72:8080 
    Content -length is 233 
    Connection the Keep - Alive 
    Cache -Control NO- Cache 
    the cookie CSS = undefined; JSESSIONID = 1B9AC25036290F7FB6823CCE1A24E541 
 
        can see the Ajax request more than a month the X- -requested- with. 
        We can use it to determine whether the request is an Ajax request. 
        If request.getHeader ( "X--Requested-With") value XMLHttpRequest, compared with Ajax asynchronous requests. It is null , compared with conventional synchronous request.
/ **  
     * Ajax is determined whether a request 
     * @param Request 
     * @return  
     * /   
    public  static  Boolean isAjax(HttpServletRequest request) {  
        return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));  
    }  

 

Guess you like

Origin www.cnblogs.com/nvsky/p/11083652.html