JSP's page pass value, database read and write garbled solution

xiaoxiao2021-03-06  18

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 *

Description: *

Copyright: Copyright (C) 2003 *

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;}}

转载请注明原文地址:https://www.9cbs.com/read-49463.html

New Post(0)