1. All pages should add <% Request.setCharacterencoding ("GB2312"); // Solve Chinese issues%> during the transfer process.
2. // Used to solve the page Chinese character problem
3. Write a Chinese transcoding method. State the text in the variable as ISO-8859-1
<%! public string getstr (string s) {string str = s; try {byte b [] = str.getbytes ("ISO-8859-1"); str = new string (b); return str;} catch Exception E) {Return NULL;}}}%> JSP dedicated to solve Chinese garbled issues, you use him to use him first,
<% = getStr (String Srs.getstring ("news"))%>
4. This class is to Unicode, I have not used it, I don't know the effect.
Import java.io.unsupportedEncodingexception;
/ ************************************************** ***** *
Title: MRX's Utility Package P> *
Description: p> *
Copyright: Copyright (C) 2003 P> *
Company: < / p> * @Author MRX [neiyouhefang@sina.com] * @version 1.0 ******************************************* ********************* /
Public class chineseutility {
Public chineseutility () {}
Public Static String UnicoDetoChinese (String Str) {try {if (str == null || str.equals (")) {return";} else {string newstr = null; newstr = new string (str.getbytes ISO8859_1 ")," GB2312 "); Return Newstr;}} catch (unsupportEncodingExcection) {E.PrintStackTrace (); returnction str;}}
Public static string chinesetounicode (string str) {try {if (str == null || str.equals (")) return" "; string newstr = null; newstr = new string (str.getbytes (" GB2312 "), "ISO8859_1"); return newstr;} catch (unsupporteencodingexcection e) {return str;}}