When accessing a Web resource, there is no corresponding result, it is possible that the filter does not release resources
Static and dynamic resources are handled differently by the code as follows: Does the ====NO2 segment end with a JSP
Import Java.io.ioexception;import Javax.servlet.filter;import Javax.servlet.filterchain;import Javax.servlet.filterconfig;import Javax.servlet.servletexception;import Javax.servlet.servletrequest;import Javax.servlet.servletresponse;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;//prevents browsers from caching dynamic resources, such as JSP resources public class FilterDemo5 implements Filter {//idea privat e filterconfig filterconfig; public void init (Filterconfig filterconfig) throws servletexception {this.filterconfig = Filterconfig; } public void DoFilter (ServletRequest req, servletresponse res,filterchain chain) throws IOException, Servletexception {//no HttpServletRequest The parent-child interface to request = (HttpServletRequest) req; HttpServletResponse response = (httpservletresponse) res; NO1 gets the URI of the resource accessed by the client, in the form/day04/login.jsp//http:string uri = Request.getrequesturi (); Static resources and dynamic resources for different cache processing, the code is as follows://no2 sentence is the end of the JSP, that is, dynamic resources IF (uri!=null && uri.endswith ("jsp")) {//NO3 If it is a dynamic resource, set three response headers to notify the browser not to cache Response.setheader ("expire S ","-1 "); Response.setheader ("Cache-control", "No-cache"); Response.setheader ("Pragma", "no-cache"); }else if (uri!=null && uri.endswith ("html")) {//no4 If it is a static resource, cache a certain amount of time String strhtml = Filtercon Fig.getinitparameter ("HTML"); Long time = System.currenttimemillis () +integer.parseint (strhtml) *1000; Time is the millisecond value response.setdateheader ("Expires", time); Response.setheader ("Cache-control", time/1000+ ""); Response.setheader ("Pragma", time/1000+ ""); }//no5 Release Resources chain.dofilter (Request,response); } public void Destroy () {}}
Filter prevents browsers from caching dynamic resources, such as JSP resources-Learning notes