?? cookiemidlet.java
字號:
package com.j2medev.chapter4;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CookieMIDlet extends MIDlet implements CommandListener {
private Display display = null;
public static final Command exitCommand = new Command("Exit",Command.EXIT,1);
public static final Command okCommand = new Command("Ok",Command.OK,1);
public void startApp() {
display = Display.getDisplay(this);
Form form = new Form("cookie");
form.append("click to send request to server");
form.addCommand(exitCommand);
form.addCommand(okCommand);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if(command == exitCommand){
destroyApp(false);
notifyDestroyed();
}else if(command == okCommand){
new Thread(){
public void run(){
try{
//使用GET方法連接服務器端
String url = "http://localhost:8080/myapp/myservlet?hello=world";
HttpConnection conn = (HttpConnection)Connector.open(url);
//設置header
conn.setRequestProperty("platform","k700");
OutputStream os = conn.openOutputStream();
os.close();
conn.close();
Alert alert = new Alert("info");
alert.setTimeout(1500);
alert.setString("send to server successfully");
display.setCurrent(alert);
}catch(IOException ex){
ex.printStackTrace();
}
}
}.start();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -