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|TextField.PASSWORD);

            Command cmdLogin = new Command("Login",Command.OK,1);
       
            frmLogin.append(username);
            frmLogin.append(password);
            frmLogin.addCommand(cmdLogin);
            frmLogin.setCommandListener(this);
     }
     
     public void startApp() throws MIDletStateChangeException{         
            display.setCurrent(frmLogin);
     }

     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)Connector.open("http://localhost/login/process.asp?q=login&tUserId="+username.getString()+"&tPassword="+password.getString());

               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
%>
ahmed_xAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
thomasbauConnect With a Mentor Commented:
int i;
                while ((i = is.read()) != -1) {
                   buffer += (char)i;      
                }

                is.close();
0
 
thomasbauCommented:
the thing just jumped off, sorry  here the details:

"is" is your inputstream
"buffer" is a String

I hope this helps
greetings
0
 
ahmed_xAuthor Commented:
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 ...
0
 
thomasbauCommented:
Think about the serverside application you want to worke with first.
:-)
0
 
ahmed_xAuthor Commented:
:-o
Serverside application?
What kind of it?
I'm using Web based Application and ASP for it.
:-l
0
All Courses

From novice to tech pro — start learning today.