<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>第二:解決jsp頁面中的中文問題: pageEncoding是jsp文件本身的編碼contentType的charset是指服務(wù)器發(fā)送給客戶端時的內(nèi)容編碼<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>第三:解決頁面數(shù)據(jù)傳輸?shù)闹形膯栴}:最佳方法是采用編碼過濾器來解決,加一個過濾器,把所有的數(shù)據(jù)都進行轉(zhuǎn)碼
<filter> <filter-name>CharacterEncodingFilter</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>encoding<filter-name> <url-pattern>/*</url-pattern> </filter-mapping>第四:HTtp(post)請求中的中文亂碼在Servlet中 添加response.setCharacterEncoding("UTF-8");第五:HTTP(get)請求中的中文亂碼問題:如果是get,需要獲取請求的字符串,然后把整個字符串進行轉(zhuǎn)換,同時需要知道原編碼,下例假設(shè)為 ISO-8859-1String JDBCNAME = (String) RequestObject("jdbcname")[0]; JDBCNAME= new String(JDBCNAME.getBytes("ISO8859-1"),"UTF-8");第六:MySQL數(shù)據(jù)庫中的中文問題:解決Mysql數(shù)據(jù)庫中文問題主要在JDBC驅(qū)動的URL上添加:&characterEncoding=UTF-8第七:Mysql數(shù)據(jù)庫在windows系統(tǒng)中,dos中顯示表中數(shù)據(jù)為亂碼,但是數(shù)據(jù)輸入與輸出均正常:這是因為windows系統(tǒng)中,默認的編碼是中文,而寫入的時候是UTF-8,此時只需要設(shè)置 set names gb2312 即可注意事項:Tomcat的默認編碼是iso-8859-1,如果沒有指定的話,就會使用默認的編碼
新聞熱點
疑難解答