问题描述
我不是100%了解Java或过滤器。接管一些代码,我们发现Firefox中的.ZIP(大写)文件呈现为文本/纯文本。 .ZIP文件可以在IE中正确下载,但不能在Firefox中正确下载。 .zip(小写)可以在IE和Firefox中正确下载。
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.
据我所知,web.xml指向Filter类。
在调用chain.doFilter的代码的症结所在,我试图在chain.doFilter之前设置内容类型,然后检查doFilter之前和之后的内容类型。
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.
这是代码:
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());
其输出如下(大致):
Current Content Type: null New Content Type: application/zip
<Some stuff where doFilter is called />
Current Content Type2: text/plain
在Firefox中,我得到了内容类型为文本/纯文本,因此我认为由doFilter设置内容类型。
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.
有关发生这种情况的原因的任何指针,或如何获取.ZIP文件以提示正确下载的任何指针。
Any pointers as to why this happens, or how to get a .ZIP file to prompt to download correctly.
谢谢。
推荐答案
doFilter ()
方法正在调用过滤器链中的下一个过滤器。
The doFilter()
method is calling the next filter in the filter chain.
过滤器链是过滤器列表,因为它们是在您的web.xml。
The filter chain is the list of filters, as they are defined in your web.xml.
因此,也许您的web.xml中有一个过滤器,确实会更改内容类型。
So, maybe there is a filter in your web.xml, that does change the content type.
但是也许更简单,在应用程序服务器的默认配置中查找mime映射,或者在web.xml中定义一个,看看是否有帮助:
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>
这篇关于javax.servlet.FilterChain在Firefox中将ContentType设置为text / plain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!