web层的尝试:
javascirpt代码,通过ajax添加请求头,可以达到返回304 not modify,但是需要js自行把数据缓存,否则返回后没有数据展示。
// var date = date_ddmmmyy(new Date(Date.parse(document.lastModified))); // var time = document.lastModified.substring(document.lastModified.indexOf(" ")); // heads ={'Last-Modified':date+time};
//set the last-modify-head if(heads){ if(heads['Last-Modified']) this._request.setRequestHeader("If-Modified-Since",heads['Last-Modified']); } //set the last-modify-hea
// // format date as dd-mmm-yy // example: 12-Jan-99 // function date_ddmmmyy(date) { var d = date.getDate(); var m = date.getMonth() + 1; var y = date.getYear(); // handle different year values // returned by IE and NS in // the year 2000. if(y >= 2000) { y -= 2000; } if(y >= 100) { y -= 100; } // could use splitString() here // but the following method is // more compatible var mmm = ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar': ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun': ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep': (10==m)?'Oct':(11==m)?'Nov':'Dec'; return "" + (d<10?"0"+d:d) + "-" + mmm + "-" + (y<10?"0"+y:y); }
后台java处理
org.springframework.web.context.request.WebRequest //check is modify if(webRequest.checkNotModified(lastModifyTime)){ return null; }