⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aspconnect.java

📁 手机连接ASP服务锻
💻 JAVA
字号:
//ConnectASP.java
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.*;

public class AspConnect extends MIDlet implements CommandListener{

public Form form = null;
public Display display = null;
public static TextField tf1 = null;
public static Command ok = null;

public AspConnect(){
	form = new Form("返回结果:");
	
	tf1 = new TextField("The rerurn result is followed!","",20,TextField.ANY);
	ok = new Command("ok",Command.SCREEN,0);
	form.append(tf1);
	form.addCommand(ok);
	form.setCommandListener(this);
}

public  void startApp(){
String retResult = "";
try{


testASP();//测试ASP连接
}catch(IOException e){
System.out.println("error");
}
notifyDestroyed();
}

void testASP()throws IOException{
String retResult = "";
try{

String uri="http://localhost/AspConnect/AspConnect.asp?message=Hello+J2ME!&IP=192.168.0.12";
HttpConnection conn=(HttpConnection)Connector.open(uri);
InputStream in=conn.openInputStream();
DataInputStream dis = new DataInputStream(in);
int ch;
while ((ch = dis.read())!=-1){

retResult = retResult + (char)ch;

}

in.close();
dis.close();
conn.close();
}catch(ConnectionNotFoundException e){
System.out.println("Http could not be opened");
}	//tf1.setChars(retResult,0,retResult.length);
	tf1.setString("你好!信息收到 !");
	display = Display.getDisplay(this);
	display.setCurrent(form);System.out.println(retResult);
	
	
}

public void pauseApp(){}
public void destroyApp(boolean unconditional){}

public void commandAction(Command com ,Displayable dis){
	if (com == ok)
	{
		destroyApp(false);
		notifyDestroyed();
	}
}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -