Pass Parameter from midlet to Servlet

Discussion in 'Software' started by jatin_1183, Mar 17, 2008.

  1. jatin_1183

    jatin_1183

    Joined:
    Mar 17, 2008
    Messages:
    1
    Hello guys,
    I m using MIDlet on client side, & Servlet on Server side,
    I can't able to send parameter from MIDlet to Servlet,
    I got value NULL in my servlet, even after in my MIDlet displaying that the data successfully sent.

    Its a base of my project
    I posted my MIDlet code below, plzz any 1 help me out with it
    --------------------------------------------------------------------------

    package Example2;

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.io.*;
    import java.io.*;

    public class PassParam extends MIDlet implements CommandListener {

    private Display dis ;
    private Form f1;
    private TextField tfName;
    private Command COMMAND_OK,COMMAND_EXIT;
    private String reqString;
    public PassParam() {
    // TODO Auto-generated constructor stub
    dis = Display.getDisplay(this);
    f1 = new Form("This is Form 1 ");
    COMMAND_EXIT = new Command("Exit",Command.EXIT,1);
    COMMAND_OK = new Command("Ok",Command.SCREEN,1);
    tfName = new TextField("Enter name ","",10,TextField.ANY);
    f1.addCommand(COMMAND_EXIT);
    f1.addCommand(COMMAND_OK);
    f1.append(tfName);
    f1.setCommandListener(this);
    }
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    // TODO Auto-generated method stub
    }
    protected void pauseApp() {
    // TODO Auto-generated method stub
    }
    protected void startApp() throws MIDletStateChangeException {
    // TODO Auto-generated method stub
    dis.setCurrent(f1);
    }

    public void commandAction(Command c, Displayable d) {
    // TODO Auto-generated method stub
    if(c == COMMAND_EXIT){
    notifyDestroyed();
    }
    else if(c == COMMAND_OK){
    Form waitForm = new Form("In Progress..");
    dis.setCurrent(waitForm);
    Thread t = new Thread(){
    public void run(){
    reqString = tfName.getString();
    doConnectToServ(reqString);
    }
    };
    t.start();
    }
    }
    public void doConnectToServ(String name){


    String reqString = tfName.getString();
    HttpConnection c = null;
    OutputStream os = null;
    InputStream in = null;

    String url = "http://localhost:8080/ServletClass/MyServlet?Name="+name;
    try{
    c = (HttpConnection) Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("CONTENT-TYPE","application/x-www-form-encoded");
    c.setRequestProperty("User-Agent",
    "Profile/MIDP-2.0 Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    /
    if(c.getResponseCode() == c.HTTP_OK){
    // this will print OK
    Form a = new Form("Output Done");
    String aa = "Data Send";
    a.append(aa);
    dis.setCurrent(a);

    }

    }
    catch (IOException ioe) {
    System.out.println("Error in IO ");
    }


    }

    }

    --------------------------------------------------
    Please help me out,
    I checked that in Servlet http://localhost:8080/ServletClass/MyServlet..?Name=foo , working well

    Thank You
     
    jatin_1183, Mar 17, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shyam
    Replies:
    1
    Views:
    1,062
  2. aarthi
    Replies:
    0
    Views:
    1,902
    aarthi
    Apr 24, 2007
  3. cisco_query

    Applet to Servlet to HTML

    cisco_query, Jan 27, 2008, in forum: Software
    Replies:
    0
    Views:
    1,195
    cisco_query
    Jan 27, 2008
  4. timoth1000

    Create Menus and Submenus in a MIDlet

    timoth1000, Apr 9, 2009, in forum: Software
    Replies:
    0
    Views:
    1,146
    timoth1000
    Apr 9, 2009
  5. siddunelogi

    unable to create MIDlet

    siddunelogi, Apr 21, 2009, in forum: Software
    Replies:
    0
    Views:
    1,210
    siddunelogi
    Apr 21, 2009
Loading...

Share This Page