jQuery in Action, 2nd edition*
The moose likes Java Micro Edition and the fly likes where i can get example konek client J2ME and server PHP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "where i can get example konek client J2ME and server PHP" Watch "where i can get example konek client J2ME and server PHP" New topic
Author

where i can get example konek client J2ME and server PHP

Haryman Triputranto
Greenhorn

Joined: Oct 05, 2010
Posts: 1
where i can get example konek client J2ME and server PHP, please help me...




i can,t connect my code J2me to server PHP.

this is my code..

package BandungMobile;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;

public class Login_User extends Form implements CommandListener {

private Display display;
private TextField userName;
private TextField password;
private Form form;
private Command Cmd_Back;
private Command Cmd_Login;
private StringItem HasilItem;
private m_BS mBS;
private String result,akhir;
private Thread thread = null;

public Login_User(Display display, m_BS mBS) {

super("Login Pengguna");
this.display = display;
this.mBS = mBS;
this.akhir = akhir;
HasilItem = new StringItem("","");

try {
Tampil();
}
catch(Exception e) {
e.printStackTrace();
}

}

public void Tampil() throws Exception {

userName = new TextField("Username : ", "", 25, TextField.ANY);
password = new TextField("Password : ", "", 30, TextField.ANY|TextField.PASSWORD);
Cmd_Back = new Command("Back", Command.BACK, 2);
Cmd_Login = new Command("Login", Command.OK, 1);
append(userName);
append(password);
addCommand(Cmd_Back);
addCommand(Cmd_Login);
setCommandListener(this);

}

public void commandAction(Command c, Displayable d) {

if (c.getLabel() == "Back") {
Menu_Utama menu_utama = new Menu_Utama(display, mBS);
display.setCurrent(menu_utama);
}
else if (c.getLabel() == "Login") {
String user = userName.getString();
String pass = password.getString();
String url = "http://localhost/KA/login.php?username="+user+"&password="+pass;

Thread alur=new koneksi(url);
alur.start();

//if (akhir.equals("Salah") == true) {
// krt.showAlert("Login Ditolak !");
//}else{
// Menu_User Menu_User = new Menu_User(display,akhir);
//display.setCurrent(Menu_User);
//}
}
}
class koneksi extends Thread{
String url=null;
String hasil=null;

public koneksi(String url) {
this.url=url;
}

public void run() {
InputStream iStrm=null;
ByteArrayOutputStream bStrm=null;
HttpConnection http=null;
try {
System.out.println(url);
http=(HttpConnection) Connector.open(url);
System.out.println("1");
http.setRequestMethod(HttpConnection.POST);
System.out.println("2");
System.out.println(http);
if (http.getResponseCode()==HttpConnection.HTTP_OK){
int ch;
System.out.println("3");
iStrm=http.openInputStream();
System.out.println("4");
bStrm=new ByteArrayOutputStream();
System.out.println("5");
while((ch=iStrm.read()) !=-1){
if ((ch!=10 && ch!=13)){
bStrm.write(ch);
System.out.println("6");
}
}
hasil=new String(bStrm.toByteArray());
System.out.println(hasil);
}
} catch (Exception e) {
System.out.println("7");
System.out.println("Terdapat kesalahan");
}
System.out.println("8");
}
}
}
 
Consider Paul's rocket mass heater.
 
subject: where i can get example konek client J2ME and server PHP