各國字符集(GB2312、JIS、ASCII 等)碼位重疊,早期本地化版本維護成本高。國際化(I18N)引入 Unicode 作為統一內碼,運行時根據 Locale/Codepage 進行雙向轉換。Java 內部使用 Unicode (UTF-16),I/O 操作必須經歷編碼轉換,環境配置不當即產生亂碼。
new String(param.getBytes("ISO-8859-1"), "UTF-8") 修正。pageEncoding 或 response.setCharacterEncoding(),瀏覽器猜測錯誤。characterEncoding=utf8 或 useUnicode=true。server.xml URIEncoding、CharacterEncodingFilter 統一處理。com.ibm.ws.webcontainer.httpRequestEncoding、com.ibm.ws.webcontainer.httpResponseEncoding 設為 UTF-8。ibm-web-ext.xmi 指定 defaultEncoding。<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>CharacterEncodingFilter(Spring 提供或自寫),forceEncoding=true。server.xml <Connector URIEncoding="UTF-8" .../>。jdbc:mysql:///db?useUnicode=true&characterEncoding=UTF-8。utf8mb4_general_ci。<meta charset="UTF-8">。