• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

where i can get example konek client J2ME and server PHP  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
}
 
I am mighty! And this is a mighty small ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!