Joke Collection Website - Blessing messages - Java garbled problem

Java garbled problem

Do you know the original code of the garbled code? If you know, switch back first, such as:

byte[]b = str . getbytes(" ISO-8859- 1 ");

Generally, the default code is ISO-8859- 1.

The form data submitted by POst generally have Chinese characters.

Before obtaining: request. setcharacterencoding(" gbk ");

Before sending Chinese data: response.setcontenttype ("text/html; charset = GBK ");

For JSP pages, before obtaining the request parameters:

& lt% request . setcharacterencoding(" GB 23 12 ")% & gt;

& lt% @ page contenttype = "text/html; charset = GBK " % & gt;

besides

string name = request . getparameter(" name ");

What you get is garbled code.

Name = new string (name. getbytes ("ISO-8859-1"), "GBK").

The Unicode value of name in the first line here is converted with ISO-8859- 1 encoding. Call the second line to get the original GBK encoding value and reconstruct the Unicode encoding of the string with the new string.