English could not be shown correctly in respond of HTTP

Hi, everyone, I am writing a class that it could connect to http://babelfish.altavista.com/ and send out a "Chinese-simp to English" translation request. And then it would print out the respond from the server which is in HTML language. Everything works alright so far except the display of the translation result. The results, including all the HTML tags and translation results, supposed to be all in English. However, only the English translation result doesn't appear correctly. There is no problem at all if I enter the same Chinese string in the program into babelfish website and translate it into English.
I also tried to convert the charset of the outputstream, which would send the request to the server, into UTF-8 since the webpage was encoded in UTF-8. Correspondingly, I also use the method toChinese() to convert the Chinese string from GBk to UTF-8 before sending it out. I tred many charsets (ASCII, UTF-8, UTF-16, GBK, ISO8859_1), but none of them work correctly.
I have already successfully translate French to English by setting the both of charsets of outputstream and inputstream to ISO8859_1.
I don't know what is wrong with it. I wish someone could point it out for me. Here is the code of this program:
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.text.html.*;
import javax.swing.text.html.HTMLEditorKit.*;
public class FormProcessor {
public static String doPost(URL url, Properties nameValuePairs) throws IOException{
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF8"));
Enumeration enume = nameValuePairs.keys();
while(enume.hasMoreElements()){
String name = (String)enume.nextElement();
String value = nameValuePairs.getProperty(name);
out.print(name);
out.print('=');
if(name.equals("trtext")) // debug if-statement
value = toChinese(value);
out.print(value);
if(enume.hasMoreElements())
out.print('&');
out.close();
BufferedReader in;
StringBuffer response = new StringBuffer();
try{
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8"));
catch(IOException e){
if(!(connection instanceof HttpURLConnection)) throw e;
InputStream err = ((HttpURLConnection)connection).getErrorStream();
if(err == null) throw e;
in = new BufferedReader(new InputStreamReader(err));
String line;
while((line = in.readLine()) != null)
response.append(new String(line.getBytes(), "ISO8859_1") + "\n");
in.close();
return response.toString();
public static String toChinese(String strvalue){
try{
if(strvalue==null)
return null;
else{
strvalue = new String(strvalue.getBytes("GBK"), "UTF8");
return strvalue;
}catch(Exception e){
return null;
public static void main(String[] args){
try{
Properties props = new Properties();
URL url = new URL("http://babelfish.altavista.com/tr");
props.put("URL", "http://babelfish.altavista.com/tr");
props.put("trtext", "中文测试");
props.put("lp", "zh_en");
System.out.println(props.getProperty("trtext"));
String r = doPost(url, props);
System.out.println(r);
catch(IOException e){
e.printStackTrace();
}Please help me solve this problem. Thank you very much!!!

The central thing to bear in mind is that Java characters should always be unicode and character encodings are only to be used when the characters are translated to and from bytes. So when you see the
new String(otherString.getBytes("xxx"), "yyy")
construction you can be pretty sure things are going wrong.
Assuming bablefish is sending it's response in UTF-8 (which is logical) then your UTF-8 input reader will suffice to do the job. No further transliteration should be required except, possibly, if you output the results to a file. In that case you simply use and OutputStreamWriter with the appropriate encoding.

Similar Messages

  • Simulation Loop: Code could not be generated correctly for this VI

    Running LabView Simulation 8.2 on Windows XP laptop.  I have a Simulation Loop that keeps generating the following error message:
    "Simulation Loop: Code could not be generated correctly for this VI"
    The only reference I can find in my searches is to using an RTX target, which does not apply.  When I click on Show Error it just highlights the Sim Loop
    Any ideas on how to debug this?

    Perhaps you can start removing things until you don't get the error any more. How big is the code in the loop?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • [IDCS2,Win] Chinese Traditional can not be shown correctly.

    I add a line:
    kWildFS, k_zhTW, kSDKDefStringsResourceID + index_zhTW
    in kStringTableRsrcType, and add a fr file, the contents are:
    resource StringTable (kSDKDefStringsResourceID + index_zhTW)
    k_zhTW, // Locale Id
    kEuropeanWinToMacEncodingConverter, // Character encoding converter (irp) I made this WinToMac as we have a bias to generate on Win...
    kSampleString, "選擇分類",
    // other strings ...
    but the string can not be shown correctly in IDCS2 Chinese Traditional edition. Do you known what's wrong?

    I found my Chinese Traditional string became "選擇分類", after posted. please note this is a Chinese Traditional string.

  • Could not determine the correct port

    Hi Folks!
    I can't start the EM, when I type
    $emctl (status, stop or start) dbconsole, the follow message is displayed:
    Could not determine the correct port
    Please, help me to correct this problem.
    Regards,
    Wilson

    user490256 wrote:
    Hi Folks!
    I can't start the EM, when I type
    $emctl (status, stop or start) dbconsole, the follow message is displayed:
    Could not determine the correct port
    Hi Wilson,
    What is Oracle version.
    Was it running fine earlier ?
    How did you configure dbconsole ..
    Are you any error in trace files..
    To change the dbconsole port ,
    How to change ports for DB Control 10.2.x.x [ID 395755.1]
    http://yogeedba.blogspot.com/2008/02/manual-configuration-of-dbconsole-em.html
    Regards
    Rajesh

  • Error: Subreport could not be shown

    I have check all post what ever posted as same like  this question,but i didn't find solution,
    I have update SQl 200 R2 with SP2. and using project server 2007 for showing report through report services server.
    project server  site is hosted on application server and database is on another server,and for SSRS ussing third one server where report has been deployed.
    I can check all report perfectly running with no 'sub reports' error with my domain users as administrator.
    When  domain user try to open dashboard report ,he can easily see dashboard report but he can see all  sub report but one of them show message there as
    "Error: Subreport could not be shown".
    Might be some permission issue is thare.
    Kindly do need full any body.
    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Share Point Application Developer,TCS

    Configure the SSRS configuration seting and enable integarted authnetication.
    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Sharepoint and EPM Consultant,TCS
    |
    | Twitter

  • Error "Taxes could not be calculated correctly" Message no. V1 225

    Hi,
    In FB60, while posting a vendor Invoice i am getting an error "Taxes could not be calculated correctly" however as its with green tick its allowing me to post the entry..
    Request help on solving this issue.
    Thanks.
    Kalpana

    Dear expert
        http://www.sapfans.com/forums/viewtopic.php?f=10&t=351221
          Taxes could not be calculated correctly  V1 225
    Regards
      Ajeesh.s

  • "Index could not be created: There are no active http servers known at the

    Above error shows up during Index creation on KM section of the portal.
    Checked the TREX Admin tool for Http connection . Pop up Error saying "IIS not installed. Configuration of Http communication not possible ".
    Environment : TREX 7.1 revision 43 on Windows 2003 64 Bit platform.
    During installation of standalone TREX , there were no option to select "http server".
    Please suggest, if i am missing some thing in the setup or configuration here.
    Thanks in advance .

    1.) You need to make sure that the server you are installing TREX on, also has a Web Server.  In your case, Internet Information Services (IIS 6.0) which comes with Windows Server 2003.  Once this is installed make sure that it is working (http://hostname or IP).
    2.) TREX 7.1 Rev 43 is very mature and does not involve many steps during installation.  Your only option is to choose whether you want to install it or not.
    3.) Setup of the "http connection" or "ABAP connection" is done after TREX installation.  This is done straight from TREX Administrator.
    Here is my suggestion:
    1.) Install IIS 6.0 (http://www.windowsreference.com/windows-server-2003/step-by-step-guide-how-to-install-iis-60-in-win-server-2003/)
    2.) Reinstalling of TREX is higly recommended but you can try it with the current installation.
    3.) Open up TREX Administrator (trexadmin.bat) and proceed with create IIS Websites for TREX 7.10.  The steps are located under the heading "Configuring the TREX Web Server" in the installation document.
    4.) After this, go on with Indexing.
    Regards,
    Ravi

  • HGrid hierarchy can not be shown correctly

    Hi,
    When I implement HGrid in R12, I followed HGrid example. But my result hierarchy is not show correctly.
    In my expect hierarchy, it should be 01--02--04 02--03. But in fact, my current result hierrachy is all node seems as each root node shown. A dummy root node is show on top level. Could some one can help to research my case?
    I use one custom table, there is item code and parent code in the custom table to be VL. In my VL, source attribute is item code, destination attribute is parent item code, the SQL is generate automatically.
    Following is the expect result:
    01
    --02
    ----04
    --03
    Current result is
    Root node
    --01
    ----02
    ------04
    ----03
    --02
    ----04
    --03
    --04
    Best Regards,
    Eileen
    Edited by: Eileen on Sep 20, 2009 2:38 AM
    Edited by: Eileen on Sep 20, 2009 2:39 AM

    Could some one help to look into this?
    Many thanks,
    Eileen

  • Safari could not open because server stopped responding

    My iphone4s can not open safari and it says the server has stopped responding. I have powered off several times and have cleared the safari history. nothing works. what now?

    Can you get onto any site in Safari, or can't you even open the app properly ? You could see if any of the following help.
    Try clearing Safari's cache : Settings > Safari > Clear Cookies And Data and also Clear History
    If that doesn't work then try closing Safari completely and then re-open it : from the home screen (i.e. not with Safari 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    A third option is a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Open website and then go to access links to do amendments but can not view it correctly want respond. works on explorer but no firefox

    go on website login and have to do amendments but when get the screen for amendments it want respond, can view it partially but can not view full screen do adjustments and submit. i tried it on explorer and worked but not on firefox.
    is there a setting i can adjust to be able to view 2nd screens , and find that when go to use drop down options can not do only allows me to use arrow keys or numeric keypad

    Hi,
    You can try [https://addons.mozilla.org/en-US/firefox/addon/ie-tab-plus-ff-36/?src=ss IE Tab Plus] or [https://addons.mozilla.org/en-US/firefox/addon/ie-tab/ IE Tab] to view the site inside Firefox.
    You may also want to consider the [https://support.mozilla.org/en-US/kb/reset-firefox-easily-fix-most-problems Reset Firefox] feature via '''Help''' ('''Alt''' + '''H''') > '''Troubleshooting Information''', if this is a recent problem with Firefox.

  • "Code could not be generated correctly for this VI". What does it mean?

    What do I have to do to fix this problem?

    I am getting this same error which you have already helped somebody else with. Could you be kind enough to help me too. I am attaching my VI, it contains only a Mathscript node whose commands  work perfect when typed individually on the Mathscript window.
    Regards,
    Karan Batra
    Attachments:
    mathscript_tests.vi ‏16 KB

  • The xperf logs generated on Windows 8.1 x64 could not be displayed correctly by xperf on Windows 7 x64

    I created a xperf log on Windows 8.1 x64. I can view it without any problems on Windows 8.1 x64. But when I open it wiht xperf on Windows 7 x64, the lift time of all processes is permanent, which means there is no processes start/stop during the log collection.
    It is wrong. My co-worker also met this problem on his machine. I am using xperf (WPA) version 6.3.9600.16384, which was installed a couple of weeks ago. It should be a pretty new version. Does anyone know how to solve the problem? 
    By the way, I can't attach the xperf log here because there is some sensitive information. Sorry about that.
    Thanks,
    Pu

    It's a bug fixed in FF33+.
    Simple workaround: https://bugzilla.mozilla.org/show_bug.cgi?id=1065998#c33

  • SCOM 2012r2 Favorite Report could not be shown on web console internal error 500

    Please HELP!!!
    My lab settings:
    SCOM1, SCOM2, SQL1
    Both SCOM servers were installed on 2012r2 Server and SCOM 2012 r2 Rollup3 with Web Console enabled.
    Report server installed on SQL1, MSSQL2012 with Report service, All role are installed on different servers.
    All servers are in the same domain
    ISSUE:
    I cannot run report from Favorite Report from Web Console using other non-domain computer. I got the error "500 internal server error" after run the report.
    I got this message after enable error detail report after run report from Web.
    PLEASE HELP ME!!!!!

    Hi,
    >>I cannot run report from Favorite Report from Web Console using other non-domain computer. I got the error "500 internal server error" after run the report.
    Do you mean that when you run report from Web console using domain joined computer everything works fine?
    If so, then the issue seems like IIS authentication related issue, we may need check below settings:
    Check the binding order in IIS where the web console is installed and make sure http is on top.
    Check the advanced settings on Internet Explorer. Look for the Windows integrated authentication setting and compare this setting with the management server.
    and I would like to suggest you go through the below threads for more details:
    http://social.technet.microsoft.com/Forums/systemcenter/en-US/36f68040-825c-4dce-b4f5-a4b4004259d1/scom-2012-web-console-from-remote-host-401-unauthorized-access-is-denied-due-to-invalid?forum=operationsmanagergeneral
    http://social.technet.microsoft.com/Forums/systemcenter/en-US/5d0029bd-a595-41aa-8065-2dd8fe34c0ac/scom-2012-web-console-401-unauthorized-access-is-denied-due-to-invalid-credentials?forum=operationsmanagergeneral
    Regards,
    Yan Li
    Regards, Yan Li

  • Itunes 11.1.4 is bringing visual error in my windows and could not be installed correctly...

    Itunes is losing feathers more and more with each ^upgrade~ 11.1.4 is unable to install on my computer...

    Hello Neiksl,
    Thank you for the details of the issue you are experiencing when installing iTunes.  I recommend following the steps in the article below when getting an error message trying to install iTunes:
    Issues installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/HT1926
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Application Server could not be installed correctly

    Hi, this is the message at the end of jcreator installation.
    I've before disinstalled the program, beacause it doesn't work properly, but now it don't start!!!
    Help! How can I disinstall totally the previous installation?
    Thank

    Hi,
    Please go through the "Post Uninstallation Cleanup" which is available at:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/2/Installation_ReleaseNotes.html#postuninstallcleanup
    Now try to reinstall the cretaor.
    Hope this helps.
    RK

Maybe you are looking for

  • CAD Desktop - Check out problem

    Hello all, IN productive system, user trying to check out the drawing from Content server. But system is showing an error message "ERROR WHILE CHECKING IN AND STORING:C\SAPWORKDIR\ACADM\1110002546 (dir no). 1. Content server is active & RFC connectic

  • Best Way to gather statistics in 10g

    Hi All, What is the best way to gather optimizer statistics in 10g databases? We are currently following the default automatic statistics gathering feature of 10g. But we feel it has got some shortcomings. For many of the tables the stats are not up

  • SMQ2 - Inbound Queue

    Every day, our inbound queue is flooded with thousands of entries from R3AD_CLASS queue. The Status is SYSFAIL, and the entries keep coming. I'm not running anything right now that I know of and I only expect these queues when I replicate data from R

  • IWA error in IE 7

    Hi, I am trying to configure IWA using OAM.I am using IE 7.I just created a test file in IIS Server and protected it.When I try to access the file from IE,i am getting a pop up for authentication.I believe it is because of the way IWA configured for

  • IPhone won't activate after upgrade to 2.1 Software

    I upgraded to the version 2.1 iPhone software on my original iPhone and after doing so my phone entered "emergency mode" and iTunes 8.0 gave me a message that said "info for activation could not be obtained from iPhone. Check SIM card.....". I reboot