Report of the Chinese issue of jive2 under Tomcat
Original text
JIVE Forum User Shyguy's post.
Translator:
Cherami
Xxx pay attention to XXX:
All conclusions are based on the platform:
WinNT4.0 (Simplified Chinese version) Sun JDK1.3 Tomcat4.0-b7 jive2.0.1 mysql3.23.38 org.gjt.mm.mysql.driver-2.04
Under such conditions, JIVE2.0 installed under Tomcat can not display Chinese like other JSP applications. I didn't dare to determine how many tests tell me that the Tomcat core code is always 8859_1, whether it is under the two-byte operating system. When the client enters some Chinese, request.getParameter () requests the returned string is 8859_1, so if you use system.out.println () to print into the console, it looks like "?? x?". If you add <% @ page contentType = "text / html; charSet = gb2312"%> at the start of each JSP file labels, Chinese can be displayed correctly, because tomcat know its kernel code is 8859_1 output to the client The code of PrintWriter (which is the output object of JSP) is GB2312, so PrintWriter has an angry 8859_1 to GB2312 conversion internally. That's why we always add ContentType to solve Chinese problems.
But unfortunately, when we extract strings from the database through JDBC, things are different. Take a look at the virtual code below: str = Rec.getstring (field); Can you tell me the string STR code? The answer is: GB2312 !!! (Just like mysql JDBC driver, many packages returns to the coding of strings based on the platform, such as SimpleDateFormat and JavaMail.) So, when you pass the string to PrintWrite, stupid printwriter will use again. 8859_1 -> GB2312 conversion. The poor client doesn't have a choice to see ugly ????.
Let me confuse the: request.getParameter () Returns the code of the string is 8859_1, so it looks like ?? X ?, when printing the console looks like ?? x ?, But Jive can use the string to use GB2312 encoding into the database! ! ! For example, in Post.jsp, I used the Chinese topic and content to the console before the message creation. It looks in the mysql database, select * from jivemessage will return the correct Chinese!
At the same time, I also found that response.setlocale () does not work for Chinese output.
How to solve: 1. Use string.getbytes () in front of the output to convert GB2312 strings, which is the most stupid method. 2. Run the server under the English platform. 3. The most best way is to use other Java servers!