About J2ME and C # through HTTP communication when the garbled problem (source)
Source: Internet
Author: User
The problem I am a j2me novice, just began to learn, in the attempt to J2ME and HTTP site communication when Chinese garbled. In the BBS to see some of the heroes, the most simple and efficient way is to communicate with JSP writeUTF, readUTF. But because I want to link to the destination site is C #, want to use the smallest changes can be used.
The solution! Sets the encoding in web.config in the C # project to Utf-8 (the default is Utf-8).
The following is the source code of J2ME:
Import javax.microedition.midlet.*;
Import javax.microedition.lcdui.*;
Import javax.microedition.io.*;
Import java.io.*;
import java.lang.String;;
public class Httptest extends MIDlet
{
private display display;
Public Httptest ()
{
display = Display.getdisplay (this);
}
byte[] MyData = new byte[100];
String content= "";
Dis.read (mydata,0,mydata.length);
Content = new String (MyData, "UTF-8");
Form f = new form ("HTTP Test");
F.append (content);
Display.setcurrent (f);
}
catch (Exception e)
{
System.out.println (E.tostring ());
Notifydestroyed ();
}
}
protected void Pauseapp ()
{
}
protected void Destroyapp (Boolean arg0) throws Midletstatechangeexception
{
}
}
The code is very structure simple, do not add to show and explain. I hope to be able to help beginners like me. We also hope that the veteran can love us more than the novice who love this business!!!!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service