I am a beginner in the field of J2EE. I just started to learn Chinese garbled characters when I tried to communicate with the HTTP site by using the agent. I read some of my views on BBS. The simplest and most efficient way is to communicate with JSP: WRITEUTF and READUTF. However, since the target site I want to connect to is C #, I can use it with the smallest changes.
Solution! Set the encoding in Web. config in the C # project to UTF-8 (default: UTF-8 ).
The following is the source code of j2-based architecture:
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 );
}
Protected void startApp () throws MIDletStateChangeException
{
Try {
String url = "http: // 192.168.0.25/lt;/ webform1.aspx? Phone = 13800000000 & msg1 = c2 ";
HttpConnection hc = (HttpConnection) Connector. open (url );
DataInputStream dis = new DataInputStream (hc. openInputStream ());
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 ());
Yydestroyed ();
}
}
Protected void pauseApp ()
{
}
Protected void destroyApp (boolean arg0) throws MIDletStateChangeException
{
}
}
The code structure is very simple, so it does not add instructions or instructions. I hope it will be helpful for beginners like me. I also hope that the old birds will love us more !!!!