This is a surprisingly irritating problem that I've yet to find a satisfactory solution to.
The basis of the problem, as I'm sure you're aware, is that your web.xml is configured to send all request for *.pdf to your Spring servlet. The obvious thing to try is for the servlet to recognise which requests are for static PDFs, and to then forward the request internally to that static file, but because the file will likely end with .pdf, the request will just go back through the servlet again, ad nauseum.
The only workaround for this that I've tried is to have the servlet manually read the static PDF from the servlet context (using ServletContext.getResource()
), and write it to the servlet output stream, making sure to set the various headers properly. It's not very nice.
The only option I can think of is to make the url-pattern
in web.xml
a bit less broad, so that only dynamic PDF requests get routed to the servlet, and requests for static PDFs get routed to the file, but that would require some kind of naming convention for your documents, which may not be an option.