GB2312 encoding
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Richard_Cannock
Posted On:   Thursday, January 23, 2003 11:34 AM

hi I have some chinese html message text (taken from the bbc's chinese homepage http://news.bbc.co.uk/hi/chinese/news/default1.stm ) which I have saved to a text file. The encoding for the web page is set as GB2312 in the html's meta headers Using java, I have retrieved this text from file, and set it as the content of a message using message.setContent(myString,"text/html;charset=gb2312"); Using james to send the mail and opening it in Outlook express, I find that the html is fine, but that all the chinese characters appear as "?". Any suggestions?    More>>

hi


I have some chinese html message text (taken from the bbc's chinese
homepage http://news.bbc.co.uk/hi/chinese/news/default1.stm ) which I
have
saved to a text file. The encoding for the web page is set as GB2312 in
the
html's meta headers


Using java, I have retrieved this text from file, and set it as the
content
of a message using


message.setContent(myString,"text/html;charset=gb2312");


Using james to send the mail and opening it in Outlook express, I find
that
the html is fine, but that all the chinese characters appear as "?".


Any suggestions?


cheers.

   <<Less

Re: GB2312 encoding

Posted By:   James_Bayer  
Posted On:   Thursday, January 23, 2003 02:03 PM

if possible, make sure the contents of the myString variable are correct by checking them out. the easiest way to do that quickly is to launch a awt or swing app to see if it renders the chars correct...don't forget to add this to you imports:
import javax.swing.*;




JFrame frame = new JFrame( "Character Test" );
frame.setSize( 400, 400 );
frame.getContentPane().add( new JLabel( myString ) );
frame.setVisible( true );



if that works, then you know that the problem is with the email portion of your app and it may be as simple as modifying the "text/html;charset=gb2312" string. if that doesn't work, then you may have to use other methods to read the text properly in the first place.


byte[] bytes = myString.getBytes(); //or read the bytes from the file into the bytes array here
String strEncoding = "GB2312"; //this may not be the right string, verify that
String strString = new String( bytes, strEncoding );



now try it in the awt/swing code again and see if you have it and go from there.
About | Sitemap | Contact