Re: Default Content Type for extensionless files
pauledavis@gmail.com wrote:
Fritz,
I'd recommend that you use a servlet filter. You will still need
something that maps files to content types but, a servlet filter along
the lines of the following should get you going.
public class ContentTypeFilter implements Filter {
public void doFilter(
ServletRequest req,
ServletResponse resp,
FilterChain chain)
throws IOException, ServletException {
String contentType = lookupType(req);
resp.setContentType(contentType);
chain.doFilter(req,resp);
}
private String lookupType(ServletRequest req){
// Implement me
return "text/html"; // sample default value
}
}
Just implement your content type lookup method, and add the reference
to the filter in your web.xml and you should be good to go.
hth
Hi Paule,
that's an option. I even took a shortcut and wrote it directly into the
servlet which delivers the files, since the content returned is always
html. A little bit jacky but so what.
However, I still get "text/plain". I guess that Tomcat or Apache is
overwritting the content type after I set it?
Fritz