JSP開發應用是,中文亂碼是個比較常見的問題,其根源是:Web容器默認的字符處理編碼是ISO-8859-1。
實例一、JSP頁面顯示時
<html> <head> <title>中文亂碼——JSP頁面顯示時</title> </head> <body> <center> <br/> <h1>木蘭辭擬古決絕詞柬友</h1> <p>人生若只如初見,何事秋風悲畫扇。</p> <p>等閑變卻故人心,卻道故人心易變。</p> <p>驪山語罷清宵半,淚雨霖鈴終不怨。</p> <p>何如薄幸錦衣郎,比翼連枝當日愿。</p> </center> </body> </html>
運行結果:
解決方法:為其指定中文字符集,<html>前加入
<%@ page contentType="text/html;charset=gb2312" %>
實例二、JSP頁面傳遞中文參數時
注冊頁面:
<%@ page contentType="text/html;charset=gb2312" %> <html> <head> <title>中文亂碼——JSP頁面傳遞中文參數時</title> </head> <body> <h2>申請賬號:</h2> <form action="userMsg.jsp" method="POST"> <p>郵箱: <input type="text"name="email" id="email"/><p/> <p>昵稱: <input type="text"name="nickname" id="nickname"/><p/> &n
bsp; <p>密碼: <input type="password"name="password" id="password"/><p/>
新聞熱點
疑難解答