演示控制客户端浏览器的缓存时间

package com.javaweb.yanzhengma;
//演示控制客户端浏览器的缓存时间
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class ServletHuancunTime
 */
@WebServlet("/servletHuancunTime")
public class ServletHuancunTime extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletHuancunTime() {
        super();
        // TODO Auto-generated constructor stub
    }


/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("我是中国人");
//控制缓存的时间
//从当前的时间开始缓存啦10秒钟,过了10秒钟后还要去服务器拿去数据
response.setDateHeader("Expires", System.currentTimeMillis()+10000);//时间是从1970年1月1日0时0分0秒开始计时
}


/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}


}

你可能感兴趣的:(Javaweb)