自动识别wildfly10中的mime类型

时间:2017-08-10 11:59:36

标签: utf-8 wildfly mime-types wildfly-8 wildfly-10

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

$img=wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');

因此,它将内容类型设置为所有文件类型的“text \ html”,对于css也是如此,浏览器拒绝在浏览器上加载css并显示错误。

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

但是上面的工作在jboss 6中 我试过设置

Resource interpreted as Stylesheet but transferred with MIME type text/html:
在standalone-full.xml中,但这不起作用。它如何自动识别文件内容类型?

1 个答案:

答案 0 :(得分:1)

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

因此,如果您需要servlet过滤器不与text/html之外的其他内容进行交互,只需使用 servlet过滤器url-pattern

例如,您可以使用这样的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等资源。