Tomcat html 静态文件中文乱码
代码上传到Tomcat 服务器当中,jsp文件正常,html文件中文乱码
-
html 页面标签设置编码为utf-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
tomcat conf/serve.xml 文件,添加编码 URIEncoding=“UTF-8”
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
-
bin/catalina.bat (jvm的编码)
在catalina.bat 中set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"
下面 添加 :-Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8
set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%" -Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8
-
conf/web.xml 当中修改编码
找到以下位置
<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>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
更改为
<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>
配置完毕后重启tomcat