Directly on code:
public class Weixinfilter implements filter{private static Logger Logger = Loggerfactory.getlogger (Weixinfilter.class); public void init (Filterconfig fconfig) throws servletexception {} public void Destroy () {} public void Dofilter (servletre Quest Request, Servletresponse response, Filterchain chain) throws IOException, servletexception {httpservletrequest req
= (httpservletrequest) request;
HttpServletResponse resp = (httpservletresponse) response;
String Requesturl = Req.getrequesturl (). toString ();
String querystr = req.getquerystring (); Add timestamp to static resource, to avoid cache if (Requesturl!= null && (Requesturl.endswith (". js") | | reques Turl.endswith (". css"))) {//static resource String Newurl = null; if (Stringutils.isnotblank (QUERYSTR) && Querystr.trim (). IndexOf (Parameterconfig.static_tail) = = 1) {Newurl = Requesturl + "?" + Querystr + "&" + Parametercon Fig.
Static_tail + new Date (). GetTime ();
Resp.sendredirect (Newurl); Req.getrequestdispatcher (NEWurl). Forward (request, response);
Return } if (Stringutils.isblank (querystr)) {Newurl = Requesturl + "?" + Parameterconfig.static_tail + new Date (). GetTime ();
Sendredirect (Newurl);
Req.getrequestdispatcher (Newurl). Forward (request, response);
Return } try{Chain.dofilter (request, response);}
catch (Exception e) {logger.error (e.tostring ());} return; The public class Parameterconfig {/** static resource to prevent caching, plus timestamp flag */public static final String static_tail = "__oawx_t=";
Configure the filter on the line, the effect is as follows:
In the development phase is still more useful.
The above is a small series to introduce the use of the filter mechanism to static resource URL plus timestamp, to prevent JS and CSS file caching related content, I hope to help everyone.