ahmed_x
asked on
StreamConnection, How can i pass my data to HTTP from MIDlet?
Dear Experts,
Im learning bout StreamConnection in J2ME, I want to pass my data that is username and password from my MIDlet to http.
Im using j2sdk1.4.1 dan WTK2.1. In emulation after message "form wants to send and receive data using the network. This will use airtime and mau result in charge. Is it OK to use Airtime?" then i choose "Yes" there is no work. What happen? i don't know.
Then, how can i pass the data from Midlet to HTTP?
Here is my code : (please give me correction and suggestion)
---------
form.java
----------
import java.util.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet. *;
import javax.microedition.lcdui.* ;
public class form extends MIDlet implements CommandListener{
private Display display;
private Form frmLogin;
private TextField username;
private TextField password;
public form(){
display = Display.getDisplay(this);
frmLogin = new Form("Login");
username = new TextField(" User Name","",25,TextField.ANY) ;
password = new TextField(" Password ","",45,TextField.ANY|Text Field.PASS WORD);
Command cmdLogin = new Command("Login",Command.OK ,1);
frmLogin.append(username);
frmLogin.append(password);
frmLogin.addCommand(cmdLog in);
frmLogin.setCommandListene r(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(frmLogi n);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void login(){
String kata = "No Result";
StreamConnection conn = null;
InputStream in = null;
StringBuffer data = new StringBuffer();
try{
//data yang akan dikirim adalah username dan password
conn = (StreamConnection)Connecto r.open("http://localhost/login/process.asp?q=login&tUserId="+ username.g etString() +"&tPasswo rd="+passw ord.getStr ing());
in = conn.openInputStream();
/*
What should be coded here? Plz help...:-(
????
*/
}
catch(IOException e){
System.err.println("The Connection cannot be established");
}
}
public void commandAction(Command c, Displayable d){
String label = c.getLabel();
if (label.equals("Login")) login();
}
}
-----------
process.asp
-----------
<!--#include file="function.asp"-->
<%
response.buffer = true
if request("q") = "login" then
if valUser(request("tUserId") ,request(" tPassword" )) then
session("userid")=request( "tuserId")
response.Write("welcome")
else
response.write "unregistered"
end if
%>
-----------
function.asp
-----------
<%
response.buffer = true
function checkUserID(userid)
sql = "SELECT * FROM user WHERE user_id = '"&userid&"'"
%><!--#include file="opendb.inc"--><%
if rs.eof then checkUserID = false else checkUserID = true
end function
function valUser(userid,password)
sql = "SELECT * FROM user WHERE user_id = '"&userid&"' AND password = '"&password&"'"
%><!--#include file="opendb.inc"--><%
if rs.eof then valUser = false else valUser = true
end function
%>
------------
opendb.inc
------------
<%
openDB = "driver={Microsoft Access Driver (*.mdb)};" & "dbq=" & server.mapPath("data.mdb")
set rs = server.createObject("ADODB .recordSet ")
rs.Open sql, openDB, 2, 3
%>
Im learning bout StreamConnection in J2ME, I want to pass my data that is username and password from my MIDlet to http.
Im using j2sdk1.4.1 dan WTK2.1. In emulation after message "form wants to send and receive data using the network. This will use airtime and mau result in charge. Is it OK to use Airtime?" then i choose "Yes" there is no work. What happen? i don't know.
Then, how can i pass the data from Midlet to HTTP?
Here is my code : (please give me correction and suggestion)
---------
form.java
----------
import java.util.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.
import javax.microedition.lcdui.*
public class form extends MIDlet implements CommandListener{
private Display display;
private Form frmLogin;
private TextField username;
private TextField password;
public form(){
display = Display.getDisplay(this);
frmLogin = new Form("Login");
username = new TextField(" User Name","",25,TextField.ANY)
password = new TextField(" Password ","",45,TextField.ANY|Text
Command cmdLogin = new Command("Login",Command.OK
frmLogin.append(username);
frmLogin.append(password);
frmLogin.addCommand(cmdLog
frmLogin.setCommandListene
}
public void startApp() throws MIDletStateChangeException
display.setCurrent(frmLogi
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void login(){
String kata = "No Result";
StreamConnection conn = null;
InputStream in = null;
StringBuffer data = new StringBuffer();
try{
//data yang akan dikirim adalah username dan password
conn = (StreamConnection)Connecto
in = conn.openInputStream();
/*
What should be coded here? Plz help...:-(
????
*/
}
catch(IOException e){
System.err.println("The Connection cannot be established");
}
}
public void commandAction(Command c, Displayable d){
String label = c.getLabel();
if (label.equals("Login")) login();
}
}
-----------
process.asp
-----------
<!--#include file="function.asp"-->
<%
response.buffer = true
if request("q") = "login" then
if valUser(request("tUserId")
session("userid")=request(
response.Write("welcome")
else
response.write "unregistered"
end if
%>
-----------
function.asp
-----------
<%
response.buffer = true
function checkUserID(userid)
sql = "SELECT * FROM user WHERE user_id = '"&userid&"'"
%><!--#include file="opendb.inc"--><%
if rs.eof then checkUserID = false else checkUserID = true
end function
function valUser(userid,password)
sql = "SELECT * FROM user WHERE user_id = '"&userid&"' AND password = '"&password&"'"
%><!--#include file="opendb.inc"--><%
if rs.eof then valUser = false else valUser = true
end function
%>
------------
opendb.inc
------------
<%
openDB = "driver={Microsoft Access Driver (*.mdb)};" & "dbq=" & server.mapPath("data.mdb")
set rs = server.createObject("ADODB
rs.Open sql, openDB, 2, 3
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, thank you so much, i got it...:-)
Well are there any ideas from all of you experts to develop any simple aplication using HTTP Connections? please ...
Well are there any ideas from all of you experts to develop any simple aplication using HTTP Connections? please ...
Think about the serverside application you want to worke with first.
:-)
:-)
ASKER
:-o
Serverside application?
What kind of it?
I'm using Web based Application and ASP for it.
:-l
Serverside application?
What kind of it?
I'm using Web based Application and ASP for it.
:-l
"is" is your inputstream
"buffer" is a String
I hope this helps
greetings