javax.servlet.FilterChain setting ContentType as text/plain in Firefox

二次信任 提交于 2019-12-12 06:09:35

问题


I'm not 100% clued up on Java, or Filters. Taking over some code and we have discovered that .ZIP (uppercase) files in Firefox are rendered as text/plain. The .ZIP file downloads correctly in IE but not Firefox. A .zip (lowercase) downloads correctly in both IE and Firefox.

As far as I can make out the web.xml points to a Filter class. At the crux of the code where chain.doFilter is called I've tried to set the content type before the chain.doFilter, and then check what the content type is before and after doFilter.

This is the code:

LOG.debug("Current Content Type: " + response.getContentType());
response.setContentType("application/zip");
LOG.debug("New Content Type: " + response.getContentType());

chain.doFilter(request, response);

LOG.debug("Current Content Type2: " + response.getContentType());

The output of this is as follows (roughly):

Current Content Type: null New Content Type: application/zip

<Some stuff where doFilter is called />

Current Content Type2: text/plain

In Firefox I get the content type as text/plain so I think its the doFilter setting the content type.

We don't have the option of changing the extension as these are files coming from an external source so cannot be changed.

Any pointers as to why this happens, or how to get a .ZIP file to prompt to download correctly.

Thanks.


回答1:


The doFilter() method is calling the next filter in the filter chain.

The filter chain is the list of filters, as they are defined in your web.xml.

So, maybe there is a filter in your web.xml, that does change the content type.

But maybe it is simpler, look for mime mapping either in the default configuration of your application server, or define one in your web.xml and see if that helps:

<mime-mapping>
    <extension>ZIP</extension>
    <mime-type>application/zip</mime-type>
</mime-mapping>


来源:https://stackoverflow.com/questions/28610752/javax-servlet-filterchain-setting-contenttype-as-text-plain-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!