Code as requested, Hope this helps mate:-
package com.my.filters; /** * <p>Title: CacheFilter</p> * <p>Description: This filter sets headers for all requests directed via the * filter mappings. This allows the browser to be forced to use * the cached version of the file. </p> * * Most of the work required by this filter is done via the configuration parameters * within the web.xml deployment descriptor as follows:- * * <filter> * <filter-name>BrowserCache</filter-name> * <filter-class> com.my.filters.CacheFilter</filter-class> * <init-param> * <param-name>Cache-Control</param-name> * <param-value>private,max-age=3600</param-value> * </init-param> * <init-param> * <param-name>Pragma</param-name> * <param-value>cache</param-value> * </init-param> * </filter> * * <filter-mapping> * <filter-name>BrowserCache</filter-name> * <url-pattern>*.gif</url-pattern> * </filter-mapping> * <filter-mapping> * <filter-name>BrowserCache</filter-name> * <url-pattern>*.css</url-pattern> * </filter-mapping> * <filter-mapping> * <filter-name>BrowserCache</filter-name> * <url-pattern>*.js</url-pattern> * </filter-mapping> * * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.42 **************************************************************************** */ import com.ieseries.core.Constants; import java.io.IOException; import java.util.Enumeration; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Project Core */ public class CacheFilter implements Filter { FilterConfig objFilterConfig; // Create a log attribute to allow access to log files private static final Log log = LogFactory.getLog(CacheFilter.class); private static final String VERSION_STRING = CacheFilter.class.getName() + '/' + Constants.VERSION_NUMBER; /** * init * @param filterConfig the filter configuration object */ public void init(FilterConfig filterConfig) { this.objFilterConfig = filterConfig; } /** * doFilter * @param req the ServletRequest object * @param res the ServletResponse object * @param filterChain the FilterChain * @throws IOException * @throws ServletException */ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { if (log.isDebugEnabled()) log.debug("Doing Filter Cache"); HttpServletResponse response = (HttpServletResponse) res; // set the provided HTTP response parameters Enumeration enu = objFilterConfig.getInitParameterNames(); while ( enu.hasMoreElements() ) { String headerName = (String) enu.nextElement(); // response.setHeader(headerName, objFilterConfig.getInitParameter(headerName)); // RG : use addHeader not setHeader so multiple headers can be added... if (log.isDebugEnabled()) log.debug("Setting Header : " + objFilterConfig.getInitParameter(headerName)); response.addHeader(headerName, objFilterConfig.getInitParameter(headerName)); } // pass the request/response on to the rest of the filters filterChain.doFilter(req, response); } /** * toString * @return string containing the version information */ public String toString() { return VERSION_STRING; } /** * destroy */ public void destroy() { if (log.isDebugEnabled()) log.debug("Destroy Cache Filter"); this.objFilterConfig = null; } } -----Original Message----- From: Bello Martinez Sergio [mailto:[EMAIL PROTECTED] Sent: 17 January 2006 07:12 To: Tomcat Users List Subject: RE: Images caching Hi Rob Gregory, I would thank a lot those code examples about setting headers with filters. I've read a lot about this problem yesterday and I've discovered that there are a problem with IE6 images caching, so I'm very interested in the workaround you've suggested. Thanks a lot (thanks to Alex Hyde, too) > -----Mensaje original----- > De: Rob Gregory [SMTP:[EMAIL PROTECTED] > Enviado el: martes, 17 de enero de 2006 1:12 > Para: 'Tomcat Users List' > Asunto: RE: Images caching > > Hey Guys, > > We had the exact same issue when last tested for performance and even thou > the image had not changed the webapp made a request back to the server to > check... I resolved this by setting headers on the images when they were > originally served up by Tomcat (using a servlet filter). I can post code > examples if needed. > > Hope this helps. > Rob Gregory > > -----Original Message----- > From: ALEX HYDE [mailto:[EMAIL PROTECTED] > Sent: 16 January 2006 23:38 > To: Tomcat Users List > Subject: Re: Images caching > > Hey Bello, > > I'm fairly new to this but don't mind putting my two > pence worth in. > > I'm not that sure about the client side but I've heard > mention of something called Squid which can cache > static content quite well and would sit as a proxy in > front of Tomcat. > > Gluck > > --- Bello Martinez Sergio <[EMAIL PROTECTED]> wrote: > > > Hi all, > > I have a web application in Tomcat 5.0 (standalone) > > that does image swapping > > for some mouse events. > > My problem is that IE does a GET request everytime I > > change an image's src > > atribute. No matter if I > > preload all document images with imgX=new Image(); > > imgX.src = '...', the > > browser always request the image > > from the server when I put the mouse over an image. > > I've tried to change > > browser cache settings, too. > > Does anybody know how can I do to avoid this? I've > > read resin lets you > > define things like '<cache-mapping > > url-pattern="*.gif" expires="60D"/>' > > Is there a way to do this with Tomcat? I would like > > to avoid using Apache > > for the moment. > > Thanks a lot, > > > > Sergio > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > > > > > ___________________________________________________________ > To help you stay safe and secure online, we've developed the all new > Yahoo! > Security Centre. http://uk.security.yahoo.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]