Utf 8 在wildfly10中自动识别mime类型
为了支持我们在Servlet过滤器中添加的所有UTF-8字符Utf 8 在wildfly10中自动识别mime类型,utf-8,wildfly,mime-types,wildfly-8,wildfly-10,Utf 8,Wildfly,Mime Types,Wildfly 8,Wildfly 10,为了支持我们在Servlet过滤器中添加的所有UTF-8字符 servletResponse.setContentType("text/html; charset=" + "UTF-8"); servletRequest.setCharacterEncoding(servletResponse.getCharacterEncoding()); 因此,对于所有文件类型和css,它都将内容类型设置为“text\html”,并且浏览器拒绝将其加载为css,但在浏览器上出现错误 Resource in
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:
但是上面的方法在JBoss6中有效
我试着设置
<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>
MyServletFilter
[...]
[...]
MyServletFilter
*.jsp
当然,您需要检查此模式是否符合您的目录结构以及访问动态text/html
内容的其他方式
因此,像这样的资源不会被您的特定筛选器更改。您不需要这样做-默认编码是UTF-8。我会将其全部删除,因为服务器会为您找到答案。@stdunbar如果我删除了它,那么它将无法保存utf-8字符,因为它会将该字符修改为其他字符