Tomcat運行亂碼通常是由于字符編碼設置不正確導致的。以下是幾種可能的解決方法:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
String str = new String(亂碼字符串.getBytes("ISO-8859-1"), "UTF-8");
以上是一些常見的解決方法,具體應該根據你的具體情況進行調整和嘗試。