gpt4 book ai didi

utf-8 - 自动识别wildfly10中的mime类型

转载 作者:行者123 更新时间:2023-12-01 04:47:19 25 4
gpt4 key购买 nike

为了支持我们在 Servlet 过滤器中添加的所有 UTF-8 字符

servletResponse.setContentType("text/html; charset=" + "UTF-8");
servletRequest.setCharacterEncoding(servletResponse.getCharacterEncoding());

因此,它将所有文件类型和 css 的内容类型设置为“text\html”,并且浏览器拒绝加载 css,并在浏览器上出错。
Resource interpreted as Stylesheet but transferred with MIME type text/html:

但以上适用于 jboss 6
我试过设置
<servlet-container name="default">
<jsp-config mapped-file="false" development="true"/>
<websockets/>
<mime-mappings>
<mime-mapping name="css" value="text/css"/>
<mime-mapping name="msi" value="application/x-msi"/>
</mime-mappings>
</servlet-container>

在standalone-full.xml 中,但这不起作用。它如何自动识别文件内容类型?

最佳答案

您的 servlet 过滤器确实不是支持所有 UTF-8 字符的最佳答案,正如您所注意到的,这个选择很奇怪,但我不会讨论它,因为这不是您的问题。

因此,如果您需要您的 servlet 过滤器不与除 text/html 之外的其他内容交互,只需使用 servlet 过滤器 url 模式 .

例如,你可以有一个像这样的 servlet 过滤器定义:

<filter>
<filter-name>MyServletFilter<filter-name>
<filter-class>[...]</filter-class>
<init-param>
[...]
</init-param>
</filter>

<filter-mapping>
<filter-name>MyServletFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

当然,你需要检查这个模式是否符合你的目录结构和其他访问你动态的方式 text/html内容。

因此,像 http://myserver.com/myapp/myservlet/staticcontent/file.xls 这样的资源不会被您的特定过滤器改变。

关于utf-8 - 自动识别wildfly10中的mime类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45613145/

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