I think your problem is with the filter order of your Web Context , i.e. some filters, in your web context, run after your filter and override the title.
The Servlet Filter is an implementation of the Responsibility Chain template.
So you can try:
- Set the headers after calling chain.doFilter:
.
... chain.doFilter(req,res); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; //get the headers we placed in the request //based on those request headers, set some response headers if(req.getHeader("X-Wria-Download") != null){ res.setHeader("Content-Type", "application/pdf"); res.setHeader("Content-Disposition", "attachment; filename=success.pdf"); }
Thus, your code will be executed after calling Servlet and, as explained below, if your filter is first declared in web.xml, then the last setHeader code will be executed (see image below).
- make sure your filter runs last after the servlet is executed, i.e. it should be the first servlet. Filter declared as explained here :

As you can see, Filter1 (the first one declared in web.xml) is the first one that was executed before the servlet was executed, and the last one was executed after the servlet was executed. Therefore, if you want to be the last filter, select the header and then declare it as Filter1.
The order of execution is determined by the order of declaration in the deployment descriptor (web.xml):
Servlet specification (section 6.2.4):
"The order that the container uses when creating the filter chain is applied to a specific URI request as follows:
"1. First, matching matching filters is the same so that these items appear in the deployment descriptor.
"2. Then the corresponding filter mappings are the same so that these items appear in the deployment descriptor."
So, just declare it as the first filter in web.xml . Thus, this is the most recent header filter. And, of course, set the title to your code after calling chain.doFilter , as already mentioned.