JSP development Servlet solves the problem of Web Page cache, jspservlet

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.