gpt4 book ai didi

javax.servlet.FilterChain 在 Firefox 中将 ContentType 设置为 text/plain

转载 作者:行者123 更新时间:2023-12-01 11:53:32 26 4
gpt4 key购买 nike

我对 Java 或过滤器并不是 100% 了解。接管一些代码,我们发现 .ZIP(大写)文件在 Firefox 中呈现为文本/纯文本。 .ZIP 文件可以在 IE 中正确下载,但不能在 Firefox 中正确下载。 .zip(小写)可以在 IE 和 Firefox 中正确下载。

据我所知,web.xml 指向 Filter 类。在调用 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>

关于javax.servlet.FilterChain 在 Firefox 中将 ContentType 设置为 text/plain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28610752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com