Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

StreamConnection, How can i pass my data to HTTP from MIDlet?

Posted on 2004-09-12
7
Medium Priority
?
346 Views
Last Modified: 2008-01-09
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
%>
0
Comment
Question by:ahmed_x
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
thomasbau earned 500 total points
ID: 12072769
int i;
                while ((i = is.read()) != -1) {
                   buffer += (char)i;      
                }

                is.close();
0
 

Expert Comment

by:thomasbau
ID: 12072789
the thing just jumped off, sorry  here the details:

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

I hope this helps
greetings
0
 

Author Comment

by:ahmed_x
ID: 12081940
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
 

Expert Comment

by:thomasbau
ID: 12090820
Think about the serverside application you want to worke with first.
:-)
0
 

Author Comment

by:ahmed_x
ID: 12107637
:-o
Serverside application?
What kind of it?
I'm using Web based Application and ASP for it.
:-l
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MAC Filtering: MAC filtering is like handing a list of names to a doorman. If someone comes to the door and mentions a name, this name is checked by the doorman on his list and granted or denied access by this. This means that if someone menti…
Multi-source agreements are important because they set standards that all manufacturers should follow to ensure that devices are compatible with multiple vendors. The multi-source agreement (MSA) is an agreement that establishes how multiple vendors…
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question