On the JSP page Chinese problem

  Torture of a night, finally. Displayed to the browser to normal, and then through the form submission is also normal. Here, in order to check for:

 First of all, this line of code is needed. And then last night to a night to also understand, without first writing page code, which is below the pageEncoding, the Charest code is modified to go, do not correct.

<%@ page contentType="text/html; charset=gb2312" pageEncoding="UTF-8"%>

Then, in the HTML file header files, also need the following a line of code:

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

The above two lines of code, can achieve the browser to display the Chinese garbled problem.

Have to say that last night, because the cache of eclipse, estimates for the front of the many times, because the eclipse cache, the output is the wrong page.

Suggest that you test, through the browser to refresh.

There is also a garbled is crawling in the form Chinese and then displayed is the Chinese garbled, write a method, can solve this problem:

public String codeString(String s)
    String str=s;
    try{byte b[] = str.getBytes("ISO-8859-1");
        str = new String(b);
        return str;
        }catch(Exception e)
            return s;

Then by calling this method, we can solve the garbled.

Posted by Barry at November 18, 2013 - 1:12 AM