|
我用ktool2.1执行之后,系统显示是“3”,是不是说连接已经建立了,但是没有得到Connection.HTTP_OK???望大家指教~~~~谢谢了~~~顺便说一下,我设了ktool里面的Network monitoring,但是窗口里面什么显示都没有。。。。
import java.io.*;
import java.lang.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class testinput extends MIDlet implements CommandListener
{
private Command exitCommand;
private Display display;
private Form txmain;
private String buf1;
private String buf2;
private static String defaultURL="http://yahoo.com";
public testinput()
{
txmain=new Form("The connection condition is:");
buf1=new String("connection is sucessful!");
buf2=new String("connection is failed!");
exitCommand=new Command("EXIT", Command.EXIT, 1);
display=Display.getDisplay(this);
txmain.addCommand(exitCommand);
txmain.setCommandListener(this);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void startApp()
{
HttpConnection conn=null;
try
{
conn=(HttpConnection)Connector.open(defaultURL, Connector.READ);
conn.setRequestMethod(HttpConnection.GET);
}
catch(ConnectionNotFoundException e)
{
System.out.println("1");
}
catch(IOException e)
{
System.out.println("2");
}
try
{
if(conn.getResponseCode()==HttpConnection.HTTP_OK)
{
txmain.append(buf1);
}
}
catch(Exception e)
{
System.out.println("3");
}
display.setCurrent(txmain);
}
public void commandAction(Command x, Displayable s)
{
if(x==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
}; |
|