JSP development Servlet solves the problem of Web Page cache, jspservlet
JSP development-Servlet for solving web page cache Problems
(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 );}}
The above is a detailed explanation of the Servlet solution for Web Cache instances. If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article and hope to help you. Thank you for your support for this site!