I'm confused by what you mean by that. Are you saying I need to somehow rewrite the class of the FilterChain object passed to my filter?
To be clear, I'm trying to modify the response that comes back from the service. I have a header that I may or may not need to set based on the response code. I believe the service sets the response code? On Thu, Mar 13, 2014 at 6:20 PM, Martin Gainty <mgai...@hotmail.com> wrote: > you'll need to pass your modified response to service method of servlet > which is *in* the filterChain > > > ApplicationFilterChain::internalDoFilter(ServletRequest request, > ServletResponse response) > throws IOException, ServletException > > { > ............ > servlet.service(request, response); > > ........... > > } > > Martin > > > > > > > > Date: Thu, 13 Mar 2014 17:51:59 -0700 > > Subject: filter question > > From: catph...@catphive.net > > To: users@tomcat.apache.org > > > > I have a filter with doFilter method like this: > > > > public void doFilter(ServletRequest request, > > ServletResponse response, > > FilterChain chain) > > throws IOException, ServletException { > > HttpServletRequest req = (HttpServletRequest) request; > > HttpServletResponse resp = (HttpServletResponse) response; > > > > resp.setHeader("Cache-Control", > > "must-revalidate, max-age=0, post-check=0, > > pre-check=0"); > > > > chain.doFilter(request, response); > > } > > > > This sets the header. However, if I set the header *after* > chain.doFilter, > > the header is not set. Why is this? > > > > public void doFilter(ServletRequest request, > > ServletResponse response, > > FilterChain chain) > > throws IOException, ServletException { > > HttpServletRequest req = (HttpServletRequest) request; > > HttpServletResponse resp = (HttpServletResponse) response; > > > > chain.doFilter(request, response); > > > > resp.setHeader("Cache-Control", > > "must-revalidate, max-age=0, post-check=0, > > pre-check=0"); > > } > > > > Programmatically I can see the header is null. > > > > Has the content already been sent to the web browser after > chain.doFilter? > > If so, is there a way to delay sending data to the browser? I need to > > inspect the status code in the response before setting my header (to > > prevent 404's from being cached). > > > > Thanks, > > Brendan Miller > >