There are three main questions:
1,struts in resource file if value is Chinese, display garbled
Workaround: Use the Eclipse plug-in properties Editor
2, in the text field input Chinese display garbled
Workaround: Use the servlet filter filter
The simplest of these can be borrowed from the filters below Tomcat. Setcharacterencodingfilter in their own web.xml configuration to add Tomcat servlet_examples corresponding configuration (master can be their own match!)
My configuration is as follows:
Setcharacterencoding
Filters. Setcharacterencodingfilter
Encoding
GBK
Setcharacterencoding
*.do
3, read garbled from some database
Solution: Re-encode the part you want to display as Chinese
For example:
while (Rs.next ())
{
String col1 = rs.getstring (1);
String col2 = rs.getstring (2);
String col3 = rs.getstring (3);
float Col4 = rs.getfloat (4);
Convert character encoding
col1=new String (col1.getbytes ("iso-8859-1"), "GB2312");
Col2=new String (col2.getbytes ("iso-8859-1"), "GB2312");
Col3=new String (col3.getbytes ("iso-8859-1"), "GB2312");
} |