Set response.setHeader("Cache-Control", "max-age=60");
and compare your code with
public class DownloadServlet extends HttpServlet {
//Initialize global variables
String fileName="";
private static Logger log = Logger.getLogger(DownloadServlet.class.getName());
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
doPost(request,response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.debug("Entered DownloadServlet");
OutputStream outStream = response.getOutputStream();
fileName=request.getParameter("fileName");
log.debug("Filename:"+fileName);
String filePath = "C:\\test
reference-material";
File f=new File(filePath, fileName);
String fileType = fileName.substring(fileName.indexOf(".")+1,fileName.length());
log.debug("Filetype:"+fileType+";"+f.length());
if (fileType.trim().equalsIgnoreCase("txt")) {
response.setContentType( "text/plain" );
} else if (fileType.trim().equalsIgnoreCase("doc")) {
response.setContentType( "application/msword" );
} else if (fileType.trim().equalsIgnoreCase("xls")) {
response.setContentType( "application/vnd.ms-excel" );
} else if (fileType.trim().equalsIgnoreCase("pdf")) {
response.setContentType( "application/pdf" );
log.debug("content type set to pdf");
} else {
response.setContentType( "application/octet-stream" );
}
response.setHeader("Cache-Control", "max-age=60");
response.setContentLength((int)f.length());
response.setHeader("Content-Disposition","attachment; filename=\"SecurityPatterns.pdf\"");
response.setHeader("Cache-Control", "no-cache");
byte[] buf = new byte[8192];
FileInputStream inStream = new FileInputStream(f);
int sizeRead = 0;
while ((sizeRead = inStream.read(buf, 0, buf.length)) > 0) {
log.debug("size:"+sizeRead);
outStream.write(buf, 0, sizeRead);
}
inStream.close();
outStream.close();
}
//Get Servlet information
public String getServletInfo() {
return "DownloadServlet Information";
}
}