Servlet solves the web page cache problem, servlet web page Cache
(1) Why should we prevent the page caching problem of the browser:
Therefore, pages that do not need to be cached must be non-cached;
The Code is as follows:
Package com. lc. httpTest; import java. io. IOException; import java. io. printWriter; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; public class CacheJiejue extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response. setContentType ("text/html; charset = UTF-8"); // specify that the page does not cache response. setDateHeader ("Expires",-1); // response supported by the IE browser. setHeader ("Cache-Control", "no-cache"); response. setHeader ("Pragme", "no-cache");} public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this. doGet (request, response );}}
(2) The Code is as follows:
Package com. lc. httpTest; import java. io. IOException; import java. io. printWriter; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; public class CacheJiejue extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response. setContentType ("text/html; charset = UTF-8"); // specify that the page is not cached // response. setDateHeader ("Expires",-1); // supported by the IE browser // cache a certain period of time for one day's response. setDateHeader ("Expires", System. currentTimeMillis () + 3600*1000*24); // ensures compatibility with response. setHeader ("Cache-Control", "no-cache"); response. setHeader ("Pragme", "no-cache");} public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this. doGet (request, response );}}
How to solve the Servlet cache problem?
What happened to the cache?
Output cache can be used:
${CachedFragment1 }$ {counter }$ {cachedFragment2}
How to solve the Servlet cache problem?
Add random number after url