javax.servlet.FilterChain 在 Firefox 中将 ContentType 设置为 text/plain
javax.servlet.FilterChain setting ContentType as text/plain in Firefox
我不是 100% 了解 Java 或过滤器。接管一些代码,我们发现 .ZIP(大写)文件在 Firefox 中呈现为 text/plain。 .ZIP 文件可以在 IE 中正确下载,但不能在 Firefox 中正确下载。 .zip(小写)在 IE 和 Firefox 中都能正确下载。
据我所知,web.xml 指向过滤器 class。
在调用 chain.doFilter 的代码的症结所在,我尝试在 chain.doFilter 之前设置内容类型,然后检查 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 中,我得到的内容类型为 text/plain,所以我认为它是设置内容类型的 doFilter。
我们没有更改扩展名的选项,因为这些是来自外部源的文件,因此无法更改。
关于为什么会发生这种情况,或如何获取 .ZIP 文件以提示正确下载的任何指示。
谢谢。
doFilter()
方法正在调用过滤器链中的下一个过滤器。
过滤器链是过滤器列表,正如它们在您的 web.xml 中定义的那样。
所以,也许您的 web.xml 中有一个过滤器确实会更改内容类型。
但也许它更简单,在您的应用程序服务器的默认配置中寻找 mime 映射,或者在您的 web.xml 中定义一个,看看是否有帮助:
<mime-mapping>
<extension>ZIP</extension>
<mime-type>application/zip</mime-type>
</mime-mapping>
我不是 100% 了解 Java 或过滤器。接管一些代码,我们发现 .ZIP(大写)文件在 Firefox 中呈现为 text/plain。 .ZIP 文件可以在 IE 中正确下载,但不能在 Firefox 中正确下载。 .zip(小写)在 IE 和 Firefox 中都能正确下载。
据我所知,web.xml 指向过滤器 class。 在调用 chain.doFilter 的代码的症结所在,我尝试在 chain.doFilter 之前设置内容类型,然后检查 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 中,我得到的内容类型为 text/plain,所以我认为它是设置内容类型的 doFilter。
我们没有更改扩展名的选项,因为这些是来自外部源的文件,因此无法更改。
关于为什么会发生这种情况,或如何获取 .ZIP 文件以提示正确下载的任何指示。
谢谢。
doFilter()
方法正在调用过滤器链中的下一个过滤器。
过滤器链是过滤器列表,正如它们在您的 web.xml 中定义的那样。
所以,也许您的 web.xml 中有一个过滤器确实会更改内容类型。
但也许它更简单,在您的应用程序服务器的默认配置中寻找 mime 映射,或者在您的 web.xml 中定义一个,看看是否有帮助:
<mime-mapping>
<extension>ZIP</extension>
<mime-type>application/zip</mime-type>
</mime-mapping>