KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > pub > ServletUtils


1 package org.ejbca.ui.web.pub;
2
3 import javax.servlet.http.HttpServletResponse JavaDoc;
4 import org.apache.log4j.Logger;
5
6 /**
7  * A class containing some helpful functions used in more than one servlet, avoiding code duplication.
8  *
9  * @author tomasg
10  * @version $Id: ServletUtils.java,v 1.2 2006/09/20 15:44:56 anatom Exp $
11  */

12 public class ServletUtils {
13
14     private static Logger log = Logger.getLogger(ServletUtils.class);
15
16     /** Helper methods that removes no-cache headers from a response. No-cache headers
17      * makes IE refuse to save a file that is sent (for exmaple a certificate).
18      * No-cache headers are also autmatically added by Tomcat by default, so we better
19      * make sure they are set to a harmless value.
20      *
21      * @param res HttpServletResponse parameter as taken from the doGet, doPost methods in a Servlet.
22      */

23     public static void removeCacheHeaders(HttpServletResponse JavaDoc res) {
24         if (res.containsHeader("Pragma")) {
25             log.debug("Removing Pragma header to avoid caching issues in IE");
26             res.setHeader("Pragma","null");
27         }
28         if (res.containsHeader("Cache-Control")) {
29             log.debug("Removing Cache-Control header to avoid caching issues in IE");
30             res.setHeader("Cache-Control","null");
31         }
32     }
33
34     /** Helper methods that adds no-cache headers to a response.
35      *
36      * @param res HttpServletResponse parameter as taken from the doGet, doPost methods in a Servlet.
37      */

38     public static void addCacheHeaders(HttpServletResponse JavaDoc res) {
39         if (!res.containsHeader("Pragma")) {
40             log.debug("Adding Pragma header");
41             res.setHeader("Pragma","no-cache");
42         }
43         if (!res.containsHeader("Cache-Control")) {
44             log.debug("Adding Cache-Control header");
45             res.setHeader("Cache-Control","no-cache");
46         }
47     }
48 }
49
Popular Tags