Servlet solves the web page cache problem, servlet web page Cache

Source: Internet
Author: User

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
 

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.