在访问Tomcat上的静态资源txt文件时,出现乱码
修改apache-tomcat-8.5.35/conf/web.xml文件内容如下
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain;charset=UTF-8</mime-type>
</mime-mapping>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>fileEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
使用Notepad++打开txt文件, 把文件编码改成UTF-8-BOM格式
重启Tomcat
修改成功