You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by pe...@kisstechnologies.co.uk on 2003/05/27 13:24:43 UTC

Stopping caching in tomcat

Hi,
Im running a Tomcat/IIS app and I have a major problem in that I am using 
struts to power a set of actions in the site and the first action that is 
linked to is done as a link : /startquote.ktx?policyID=1 .  IE6 however 
caches this page and so doesnt run the action to pull up the page.  this 
causes various things not to be set up properly.
Furthermore, the index page is also cached which means that a session is 
not instatiated for the user so the first time they submit a page, they 
get a session timed out problem.
I have written a filter which I hoped would cure caching but it hasnt made 
any difference.  I know caching is a problem but I cant seem to find any 
way around it!  Has anyone got any ideas?  Putting in meta tags has never 
really worked before but maybe it will - if so what should they be?

The filter is below:

/*
 * AntiCachingFilter.java
 *
 * Created on 27 May 2003, 10:58
 */

package com.ktdev.filters;

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *
 * @author  Pete Storey
 * @version
 */

public class AntiCachingFilter extends GenericFilter {
 
    public AntiCachingFilter() {
    }
 
    /**
     *
     * @param request The servlet request we are processing
     * @param result The servlet response we are creating
     * @param chain The filter chain we are processing
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs

     */
    public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain)
    throws IOException, ServletException {
 
        HttpServletResponse httpResponse = (HttpServletResponse) response;
 
        httpResponse.setHeader("Pragma", "no-cache");
        httpResponse.setHeader("Expires", "0");
        httpResponse.setHeader("Cache-control", "no-cache, 
must-revalidate");
 
        // Go on to the next one
        chain.doFilter(request, response);
 
    }
 
}

In web.xml

  <filter>
    <filter-name>AntiCachingFilter</filter-name>
    <description>Sets anti caching headers in the response</description>
    <filter-class>com.ktdev.filters.AntiCachingFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>AntiCachingFilter</filter-name>
    <url-pattern>/*.ktx</url-pattern>
  </filter-mapping>

Thanks
Pete

Kiss Technologies

http://www.kisstechnologies.co.uk/

Please note, we have moved!

4, Percy Street
London
W1T 1DF

New permanent phone numbers:

Phone 020 7692 9922
Fax 020 7692 9923