现在正在做J2ME与Servlet之间通信的程序,但是在发送的时候总是有异常。下面是我的代码,希望各位高手指导指导。
public class httpGet extends MIDlet implements CommandListener {
public void commandAction(Command cmd, Displayable dis) {
if(cmd == downloadCommand) {
http.setName(nameF.getString());
http.setPass(passF.getString());
synchronized(this){
notify();
}
}
}
package src;
import java.io.*;
import javax.microedition.io.*;
public class HttpThread implements Runnable{
// private String url = " ";
private httpGet midlet = null;
private boolean done = false;
public static final String HOST = "http://192.168.44.88:8080/do/servlet/Select? ";
public static final String HOST1 = "http://localhost:8080/server/servlet/server ";
public static final String HOST3 = "http://192.168.44.88:8080 ";
public String name = null;
public String PassWrod = null;
public HttpThread(httpGet midlet) {
this.midlet = midlet;
}
// public void setURL (String url) {
// this.url = url;
// }
public HttpConnection openConnection() throws IOException {
HttpConnection conn = (HttpConnection)Connector.open(HOST1,Connector.READ_WRITE);
return conn;
}
public void setName(String name){
this.name = name;
}
public void setPass(String pass){
this.PassWrod = pass;
}
public void run() {
while(!done) {
synchronized (midlet) {
try{
try {
midlet.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!done) {
HttpConnection conn = openConnection();
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty( "IF-Modified-Since ", "15 Oct 2003 08:47:14 GMT ");
conn.setRequestProperty( "User-Agent ", "Profile/MIDP-2.0 Configuration/CLDC-1.1 ");
conn.setRequestProperty( "Content-Language ", "en-CA ");
conn.setRequestProperty( "Content-Type ", "application/x-www-form-urlencoded ");