Converting Chinese Characters from UTF-8 to GB2312

Hi,
I need to interact with an external system that only accepts GB2312 encoded strings as input.
I have a site that is used to capture user input before feeding the data to the system. (Refer to the following)
<%
String strName = request.getParameter("strName");
boolean serviceStatus = false;
if (request.getParameter("strName") != null)
serviceStatus=invokeTheService(strName,"text_process");
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
How can i encode the "strName" variable value to "GB2312". (Do be informed that i am unable to change the meta Content-Type to GB2312)
I had tried using the following but was unable get it right.
strName = new String(strName.getBytes("UTF-8"),"GB2312");
I had also tried using the CharsetEncoder.encode to attempt to encode it to GB2312 but kept getting a UnmappableCharacterException message.
*Correct me if i'm wrong, but UTF-8 tends to represent characters in 1,2 or 3 bytes.
In the case of chinese characters, each character is represented by 3 bytes.
GB2312 tends to represent each character in 2 bytes.
So if i have a 3 chinese character as input, the original strName.length() would return 9. whereas the Gb2312 encoded strName should return 6 ?

KeithTan wrote:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
How can i encode the "strName" variable value to "GB2312". (Do be informed that i am unable to change the meta Content-Type to GB2312)Then what is the point of converting to GB2312 if you inform the recipient that it is encoded as something other than GB2312?
>
I had tried using the following but was unable get it right.
strName = new String(strName.getBytes("UTF-8"),"GB2312");That can never ever be right. Java Strings are UNICODE encoded as UTF16. They are always encoded internally as UTF16 so your code says - convert the string to UTF8 bytes and then, even though they are UTF8 bytes and not GB2312 bytes, treat them as GB2312 bytes. That will almost certainly corrupt the String
>
I had also tried using the CharsetEncoder.encode to attempt to encode it to GB2312 but kept getting a UnmappableCharacterException message.Even if Java does support GB2312 then it is a wast of time sending GB2312 content to a client and telling the client that it is UTF-8 .

Similar Messages

  • Display chinese characters from oracle 8i database using UTF-8

    I have written a program to retrieve chinese characters from the database and display in the web page.If I change the encoding of the webpage manully it displays the chinese characters(&#27604;&#20998;&#21345;&#29255; ).Or it shows the junk characters(�������� ).Can anybody help so that do I have to do any encoding or any other settings?.I am using Jdeveloper.
    Rgds
    Ganesh
    <HTML><HEAD><TITLE>Welcome to METRO</TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <%//@ page contentType="text/html; charset=UTF-8" %>
    <%@ page import="java.io.*,java.io.InputStream,java.nio.*,java.lang.*,java.util.*,javax.naming.Context,java.sql.Connection,javax.sql.DataSource,javax.naming.InitialContext,java.sql.*" %>
    </HEAD>
    <BODY >
    <%
    String value="";
    try{
    Connection dbConn;
    Statement stmt=null;
    Context jndiCtx=new InitialContext();
    javax.sql.DataSource ds = (javax.sql.DataSource)jndiCtx.lookup( "jdbc/webdbPooledDS" );
    dbConn= ds.getConnection();
    stmt=dbConn.createStatement();
    String sql="select prog_name_LL2 from wb_prog_new_metro where table_name='SCORE_CARD'";
    ResultSet rs = stmt.executeQuery(sql);
    if( rs.next()){                    
    value=rs.getString(1);
    out.println(value);
    }catch(Exception e){
    System.out.println("Exception ="+e.getMessage());
    %>
    </BODY></HTML>

    Make sure that you have a Unicode font that supports Chinese characters. I have been testing the support of Unicode text (allows many other character and image based languages to be displayed) and have found that it depends on what fonts are available on the system you're viewing the report on. Unicode is supported in Crystal (since version 9 I believe) but it will display '?' or '[]' if there isn't a font to render the text properly.
    This font supports loads of languages: http://www.code2000.net/code2000_page.htm

  • I had a Singapore SIM in my Iphone 4S and now i'm in Hong Kong.  After I inserted Hong Kong SIM, the playlists in My Music got changed to Chinese characters from English.  How to change it back to English?  My language setting is only English

    I had a Singapore SIM in my Iphone 4S and now i'm in Hong Kong.  After I inserted Hong Kong SIM, the playlists in My Music got changed to Chinese characters from English.  How to change it back to English?  My language setting is only English

    What you have mentioned happen to me. I posted new stuff just now. https://discussions.apple.com/thread/4450344

  • How to get utf-8 Chinese Characters from Oracle DB by EJB

    We have found that after disabling JIT in weblogic, the Chinese can be displayed correctly, otherwise, it doesn't work.How come this happens?

    Thanks for all of your suggestions. It still refuses to work.
    I entered the following: ���^�E on the HTML form using the Chinese(PRC)keyboard on my Win2K box.
    I checked and verified the correct encoding in the servlet request (GB2312 for chinese characters)
    request.getParameter(xxx) yields ???
    new String(request.getParameter(xxx).getBytes("GB2312")) yields three boxes (values 20309, 27946 and 23380)
    new String(request.getParameter(xxx).getBytes("GB2312"), "UTF-8") yields nothing
    Any ideas?

  • Problems in displaying chinese characters with utf-8 encoding

    Hi,
    I got problem in displaying chinese characters in my web application.
    I am creating a web application supporting both English and Chinese charaters. What I am trying to do is:
    1. storing some chinese characters via a web page (page1) into database.
    2. retrieve the chinese characters via another web page (page2) from the database.
    Once I put the Chinese characters on the webpage (page1 in step #1), it displayes well (the readable chinese characters) before I submit this page (after submit, the data will be stored into the database).
    But when I tried to display the chiese characters via page2 in step#2, I got un-readable characters displayed.
    The running configuration is: Sun Application Server (coming and with the JSC2) and MySQL server 5.0. And I setup the database server with utf8 as character-set.
    It seems like the chinese characters got messed up throught the round-trip (from page1<----via jdbc---->database<----via jdbc------>page2).
    From the database, I found the chinese characters are there. Any helps are appreciated.

    Hi,
    I am trying to insert new record.The record may contain chineese or English data.
    I did same what u specified.
    first I converted to the byte UTF8.again,I converted byte to string using 8859_1.
    the values are not storing chinese characters.
    pls suggest me.
    below is my code.
                                  ascCode = req.getParameter("asccode");
                                  countryCode = req.getParameter("countrycode");
                                  ascName      = req.getParameter("ascname");
                                  address1     = req.getParameter("ascaddress1");
                                  address2 = req.getParameter("ascaddress2");
                                  System.out.println("ASC NAME:"+ascName);
                                  System.out.println("ADDRESS1:"+address1);
                                  System.out.println("ADDRESS2:"+address2);
                                  ascC = ascCode.getBytes("UTF8");
                                  coun = countryCode.getBytes("UTF8");
                                  ascN           = ascName.getBytes("UTF8");
                                  add1 = address1.getBytes("UTF8");
                                  add2          = address2.getBytes("UTF8");
                                  System.out.println("ASC NAME:"+ascN);
                                  System.out.println("ADDRESS1:"+add1);
                                  System.out.println("ADDRESS2:"+add2);
                                  ascCode = new String(ascC,"8859_1");
                                  countryCode= new String(coun,"8859_1");
                                  ascName = new String(ascN,"8859_1");
                                  address1 = new String(add1,"8859_1");
                                  address2 = new String(add2,"8859_1");
                                  System.out.println("ASC NAME:"+ascName);
                                  System.out.println("ADDRESS1:"+address1);
                                  System.out.println("ADDRESS2:"+address2);
    thanks.

  • Convert Chinese signs to UTF-8

    Hi there
    I am trying to find a tool, or some code, who can help me covert Chinese signs to UTF-8 format.
    The resen is that I am working on a project who has to develop a web-site containg both english and chinese text.
    So first of all to test oure setup we need some chinese signs in UTF-8 format. Later on we will develop a work.flow that will convert those files/chinese signs.
    But right now it will be a greate help to get som input on how to get this working.
    Purhaps someone has made a smalle code who take a string af chinese signs as input and create a string of UTF-8 as output??
    Regards
    Tolstrup

    To read the file:Reader in = new InputStreamReader(
      new FileInputStream(yourChineseFile), "yourChineseFile'sEncoding"));I don't know what encoding your file is in, but it's your file not mine.
    To write the data in UTF-8:Writer out = new OutputStreamWriter(new FileOutputStream(yourUTF8File), "UTF-8");

  • Who knows how to read the Chinese Characters from JDBC?

    I wrote two files. One is a jsp file, the other is java file. But in the jsp file it cannot print the Chinese characters, only can print the English characters. I have changed the Character Coding of the browser, but it has no effects. However, the java file works much fine. It can print the both English and Chinese characters.
    This is a part of my codes.
    String query="SELECT * FROM MyDB.dbo.BookList WHERE bookname like \'Java%\'";
    ResultSet rs=sm.executeQuery(query);
    rs.next();
    out.println(rs.getString(1));
    MyDB is a database in the SQL server.

    Hi,
    Did you try setting the contentType/charset of the JSP page? The default is latin, I think.
    <%@ page ... contentType="text/html; charset=character_set" ... %>
    Maybe this helps? At least it could give you a start of where to look...
    Best,
    Guy
    http://www.atomikos.com - JTA transactions

  • Why a " # " is coming while printing chinese characters from SAP script?

    Hi All,
    Facing one issue.
    We have a SAP script for printing delivery note thru T-code VL03N. The script has chinese characters in it.
    When I print this form the chinese characters that are hardcoded in the script can be seen in the print out but the ones which are coming from the table cannot be seen instead they are repalced by " # ".
    Strangely, when a debug the script or see a print preview on the screen they can be seen as it is with no problem.
    Only when I print it, on the paper print they are seen as # but the characters that are hardcoded in the script can be seen clearly on paper.
    Secondly, in Transaction FB03 which is for display of list of documents it too has some chinese characters and when I print this directly from the t-code doing Shift-F1 ( no SAP script or form is involved in this case) then the same case is there the chinese characters get replaced by a " # ".
    Any inputs or views are welcome.
    Please suggest.
    Thanks.
    Cordially,
    Saurabh.

    Hi,
    You need to set your activate multibyte functions to support.
    Long on to SAP --->right side right corner (Customized local layout) --> click --->Select options --->select tab (l18N)
    -->Check Activate multibyefunctions to support.
    log off you SAP Gui then re-log in...you can able to view multi language characters.
    Thanks,
    Nelson

  • How to send Chinese Characters from BPEL to SAP through JCA Adapter

    Hi All,
    We want to do a POC using a BPEL process to send Chinese characters to SAP System through a JCA Adapter.
    If anyone has implemented the similar requirement, please share your thoughts on how to achieve it? Or if there had been any problems?
    Also, please let us know which SAP API we can use to test this?
    Appreciate your quick help!

    Hi Srini,
    I am working on 9.0.3 EBS 11i.
    Now i am able to encode using the below code:
    in = new BufferedReader(new InputStreamReader(uploadedByteStream.getInputStream(),"UTF-8"));
    if(linetext[7]!=null&&!"".equalsIgnoreCase(linetext[7]))
    col8=linetext[7].toString();
    vendor = new String(linetext[7].getBytes("UTF-8"),"EUC_CN");
    Now i am able to encode to chinese character when the file is in ANSI encoding, i see the CSV data in some form(not chinese).
    But when the file is in UTF-8 , and i can see the CSV data in Chinese (when i open in edit plus) , the encoding is not proper. when i remove the encoding the chinese data is coming properly.
    The data i am printing on the OAF screen.
    Now my doubt is : What type of file shd i be uploading ANSI/UTF-8????
    When i see on the local jdev as sop's , the data is seen as ???? but on the screen its printing correctly.
    but the data has to be passed to pl/sql procedure.
    Regards,
    Roopa.

  • Retrieving Chinese Characters from SQL Server with JDBC

    Im having problems correctly recieving Simplified Chinese from the database (SQL Server 2000).
    Driver: sun.jdbc.odbc.JdbcOdbcDriver
    It seems that I cannot force the Results Set's getString(String s) method to the correct character encoding UTF-16. Java claims to have 16-bit characters but the native windows encoding cp1242 (somehting like that) seems to not be working for me.
    I can read it in from a unicode text file using the InputStreamReader object, and it will display correctly.
    All I ask is this: Has anyone successfully retrieved information from a database and displayed it correctly in a Swing application?
    Any help is welcome

    Thanks for the help.
    I was suspecting there was a problem with the driver. Microsoft's Driver worked perfectly for SQL 2000, but my target database is SQL 7 and the driver is not reverse compatible.
    I am looking for a Free liscenced JDBC driver that will work with SQL 7 (other than the sun.jdbc.odbc.JdbcOdbcDriver)
    Nothing fancy needs to be supported, just scrollable result sets, and basic insert, update, select, exec commands.

  • After upgrading to Mountain Lion, I cannot convert Chinese characters anymore

    I used to be able to convert Traditional Chinese to Simplified Chinese and vice versa in OS X Lion. After I upgraded it to Mountain Lion, I cannot do so anymore. It just keeps asking to run the service which I have already done it. After clicking "Run service" nothing happened.
    Any help please
    Thank you in advance

    i've called apple support hong kong and here's the solution (works on apple's app like textedit but not on MS office applications):
    1. go to /system/library/services and copy "ChineseTextConverterService" to desktop.
    2. quit all running applications.
    3. log out and log in again.
    4. move "ChineseTextConverterService" from desktop back to where it was. when asked click on "replace".
    5. log out and log in again.
    6. of course boxes of "convert text from..." under system preference/keyboard/keyboard shortcuts/services/text should be checked (turn on)
    i'm still looking for solution on how to make it work on MS office applications. if anyone knows one, pls post. thanks.

  • Converting japanese characters to UTF-8

    Hi
    I am working on a internationalized application where we display the content from Property based Resourc Bundle. The resource bundle is in Unicode format and we use UTF-8 charset in our JSP files to display it. Till this point its working perfectly. But in our application on some JSP pages we also get data from third party Components as well. For example in on of the JSP pages we get a ArrayList of some values that we need to display on the JSP page. But the problem is that this list of values is not in Unicode format. We need to convert the values in the ArrayList to their String representations that are UTF-8 compatible. We have tried a lot many number of ways but have not been able to do so. Please specify as to what should be done.

    hi,
    if your data is in unicode format then there is no issue of storing the value in ArrayList or anything.
    please check the following things,
    1.if you r getting calue from database and store it in ArrayList..please check wheather the database is unicode supporting.
    with regards,
    kss.
    (this is the sample code,
    <%@ page contentType="text/html;charset=UTF-8" %>
    <%@ page import="java.util.Hashtable" %>
    <%@ page import="rnd.DbConnection" %>
    <%@ page import="java.sql.*" %>
    <html>
    <body>
    <%
    Hashtable h = new Hashtable();
    int count = 0;
    try {
              Connection con = DbConnection.createConnection();
              Statement stmt = con.createStatement();
              String query = "select name,password from login where lang='ja'";
              ResultSet rs = stmt.executeQuery(query);
              int row = 1,coloumn = 1;
              while(rs.next()) {
                   coloumn = 1;
                   h.put(row + "table" + coloumn,rs.getString("name"));
                   coloumn++;
                   h.put(row + "table" + coloumn,rs.getString("password"));
                   count = count + 1;
                   row++;
    }catch(SQLException e) {
         System.out.println(e.getMessage());
    %>
    <table border=3 bgcolor="wheat">
         <tr>
              <td align=left>username</td>
              <td>password</td>
         </tr>
         <%
         int tr =1, tc =1;
         for(int i = 1,j = 1;i <= count;i++) {
              tc =1;
              %>
         <tr>
         <td><%= h.get(tr + "table" + tc) %></td>
         <td><% tc++; %><%= h.get(tr + "table" + tc) %></td></tr>
         <%
                   tr++;
         %>
    </table>
    </body>
    </html>
    OUTPUT
    ++++++++
    username password
    &#31169;&#12398;&#25163;&#20803;&#12395;&#12354;&#12427; &#31169;&#12398;&#25163;
    &#31169;&#12364;&#38306;&#19982;&#12375;&#12383;&#26412;&#12420; &#31169;&#12364;&#38306;
    &#20803;&#12395;&#12354;&#12427; &#20803;&#12395;

  • PDF from Word 2007 ends up with scrambled Chinese characters

    I have a problem with PDF files when converted from a Word 2007 document that includes Traditional Chinese characters and I hope someone might be able to help or point me in the right direction. After converting it to PDF via "Create PDF" from the Acrobat toolbar, the Chinese characters are all wrong. It looks like Chinese but none of the characters actually exist, it's all scrambled and useless. Converting English or German text works fine, so far, it's only the Traditional Chinese text that causes problems.
    The strange thing is that prior to installing Office 2007, all worked just fine. I could convert Chinese text from Word 2003 without any problems and other than updating to Word 2007, nothing has changed. Any idea where to start trouble shooting and how to fix it? I've already tried re-installing and reparing both Word and Acrobat but no improvement.
    OS: WinXP Professional SP3 (English system)
    Adobe: Master Collection CS4 (English)
    Acrobat: Acrobat 9 Pro v9.1.3 (English)
    PDF Maker: Conversion Settings are set to default "Smallest File Size Web"
    Word: Microsoft Office Word 2007 (12.0.6504.5000) SP2 MSO (12.0.6425.1000)
    Note: Using "Save As" and select "PDF or XPS" in Word 2007 works fine, the Chinese characters show up properly in the PDF file but I prefer using the PDF Maker from Acrobat to create my PDF files.

    I have found that WORD 2007, particularly with docx files, does some strange things to PDF files that you produce. It seems to break a perfectly good graphic into parts and send the parts to the PDF (not usually a problem unless you zoom in). We have tested with AA8 and AA7 with WORD 2007 and gotten these results. WORD 2003 worked like expected. It is almost as though MS decided to put some hooks in OFFICE 2007 for Acrobat. Normally with Acrobat, the graphics come out as a single graphic as stored in the application.
    Glad you got the character issue to work. I use a job.settings file that is distributed by a publisher to get an "optimized" form of product for posting. Of course, optimized is always in the eye of the beholder, but I have been happy with it.

  • Convert String from UTF-8 to IsoLatin1

    Hi everyone !
    I'm trying to convert a String from utf-8 to IsoLatin1, but i got somt problems.... I'm using
    actually this code, but it won't work...
    I'm getting a utf-8 html String with some data and i will write it down in latin1 to a text file
    String newString = new String(oldString.getBytes("UTF-8"), "ISO-8859-1");If i'm now writing this newString to a TextFile it contains cryptic signs like
    & # 1 3 ; or & # 1 3 7 ; or & # 1 2 8 ;(i separated this chars)
    can anyone tell me where is my fault and how can i solve this problem ?
    Thanks a lot
    Edited by: Sephiknight on Feb 23, 2008 2:41 AM

    Yes its XML, i got a web editor where i can add input (utf-8) and i want to write it down in my class to a xml file (isoLatin1).
    My code looks likte this
         public static void setEditFragment(String content, String xPath) throws Exception {
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             DocumentBuilder builder  = factory.newDocumentBuilder();
             Document document = builder.parse("3001300.xml");
             XPath xpath = XPathFactory.newInstance().newXPath();
             Node node = (Node)xpath.evaluate(xPath, document, XPathConstants.NODE);
            Charset charset = Charset.forName("ISO-8859-1");
            CharsetEncoder encoder = charset.newEncoder();    
            ByteBuffer buf = encoder.encode(CharBuffer.wrap(content));
            node.setTextContent(buf.toString()); 
               // Use a XSLT transformer for writing the new XML file
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
             DOMSource        source = new DOMSource( document );
             FileOutputStream os     = new FileOutputStream("tmp.xml");
             StreamResult     result = new StreamResult( os );
             transformer.transform( source, result ); 
         }The example from http://www.exampledepot.com/egs/java.nio.charset/ConvertChar.html looks great, but if I add my own input string i get a exception that looks like this
    java.nio.charset.UnmappableCharacterException: Input length = 1
         at java.nio.charset.CoderResult.throwException(Unknown Source)
         at java.nio.charset.CharsetEncoder.encode(Unknown Source)
         at HagerAbs.setEditFragment(HagerAbs.java:91)
         at HagerAbs.main(HagerAbs.java:108)When i write my input to the xml file it doesnt look like xml at all, it looks more like
    <synthese>& # 13;
    & # 13;
    & lt;br/& gt;& # 13;
    & lt;img class="thumb" src="http: ......{code}
    (i seperated the char so you can see)
    and this is not what i expected... how can i write it down correctly ?
    Edited by: Sephiknight on Feb 23, 2008 3:26 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Chinese Data Fields not displaying Chinese Characters

    Hi There,
    Wonder if someone can help. We are currently running reports in Crystal 8.5 but are in the process of upgrading our business systems to latest version and this includes converting all our Crystal 8.5 reports to Crystal Reports XI R2 SP4.
    During the process we are experiencing some difficulties in displaying Chinese characters, which have previously worked fine in version 8.5. The system we are running Crystal from has Oracle client 11 installed and the OS system locale is set to Chinese PRC. Our application is displaying Chinese characters properly and if we have any text fields on the report, these are also displaying properly when changing Font to Arial Unicode MS. The only thing that doesn't display properly is the field data which after checking has the correct Chinese data stored in the database. For some reason Crystal 11.5 doesn't seem to be transferring the data correctly which points to some sort of encoding problem.
    Is there something I am missing here or is there something else I need to install for this to work?
    Any hep would be appreciated.

    What is your Oracle database's language set? Is it set to UTF-8 or non UTF-8 (such as American_America.WE8ISO8859P1" )?
    There is a similar issue tracked under ID ADAPT00528561 (Crystal cannot display non-UTF-8 Chinese characters from an Oracle database ) and has been fixed and you should set the following registry key to make it effective:
    Set the following registry key "UseOSLocaleForConversion" to "Yes" under:
    HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.5\Crystal Reports\Database\Oracle

Maybe you are looking for

  • Spry Menu with submenu border?

    Hi Everyone, I'm a bit of a newbie, and I am designing a website with a spry menu (which I have since found out probably wasn't the best way to go) and I have hit a hurdle which I can't fix or find the solution to anywhere. I'm hoping it might be eas

  • HELP, the display of my macbook pro doesn't work.

    The whole thing is like this. someday i just turned it on normally after i turned it off 2 days ago. and the thing happened. i can hear the noisy form hard driver, SuperDrive , the startup tone and even after a while ,i could hear the "bo bo" when u

  • Using Country Specific Chart of Account in addition to Operational COA

    Dear Team We are implementing 16 company codes with Group COA A002 and Operational COA A001 across all companies. Out of 16 Company codes 4 company codes already went live and running successfully. We are also using one controlling area and operating

  • Problem radius authetication ACS 5.4

    Hi friends, Do you know about this problem with radius authenticaction in  ACS 5. This is la log. Best regard, Marco

  • BarCode Scanning - PO Receipts in Forms Interface

    Hi Everyone, Need a clarification on whether the following scenario is available as standard functionality in a Forms Interface (NOT using MSCA Devices) The supplier has shipped the entire quantity of the item ordered in say, 10 Boxes. I shall be sca