SoFunction
Updated on 2025-04-06

Solution to JSP display Chinese problem

In the past two days, install apache1.3.9 and add jserv and gnujsp1.0, jdk1.2.2, and jsdk2.0 under win98.
It was found that Chinese cannot be displayed normally. Either garbled or an error occurred.
After reminding from netizens, the following methods have been summarized.
1: Modify the locale: Select the locale in the control panel and set it to English (US)?nbsp;
Then start again. Everything is normal.
2: Add a statement to the jsp page:
    <%@ page contentType="text/html;charset=gb2312" %> ?
The display of King King King King is normal.
3: Add code options when compiling servlets and jsp. Compile servlets for use
    javac -encoding iso8859_1
In the zone configuration file of jsp. Modify the compile parameters to:
    compiler=builtin-javac -encoding ISO8859_1
After using this method, you can display Chinese normally without making any other changes.
4: The most rustic method is to add code transformation statements to the servlet source program. like
    try{
(new ( (new String("I love you so much")).getBytes("GBK"),"ISO8859_1"))
    }
    catch( UnsupportedEncodingException e)
    {
    .......
    }
When using this method, be careful to catch UnsupportedEncodingException