Hi friends. I'm trying to send data from a midlet to a servlet and recieve back a response from the servlet but I don't get any value in response. I've tried to print it on command window and it seems to be null yet I expect only two values "ok" or "error". Please help me check the code and let me know what I should do to get the response right on the midlet. My code is below:
Java Code:
import javax.microedition.midlet.*;//midlet class package import  
import javax.microedition.lcdui.*;//package for ui and commands  
import javax.microedition.io.*;//  
import java.io.*;  

 * @author k'owino 
//Defining the midlet class  
public class MvsMidlet extends MIDlet implements CommandListener {  

    private boolean midletPaused = false;//variable for paused state of midlet  
    //defining variables  
    private Display display;// Reference to Display object  
    private Form welForm;  
    private Form vCode;//vote code  
    private StringItem welStr;  
    private TextField phoneField;  
    private StringItem phoneError;  
    private Command quitCmd;  
    private Command contCmd;  

    //constructor of the midlet  
    public MvsMidlet() {  

        display = Display.getDisplay(this);//creating the display object  
        welForm = new Form("THE MVS");//instantiating welForm object  
        welStr = new StringItem("", "Welcome to the MVS, Busitema's mobile voter."  
                + "Please enter the your phone number below");//instantiating welStr string item  
        phoneError = new StringItem("", "");//intantiating phone error string item  
        phoneField = new TextField("Phone number e.g 0789834141", "", 10, 3);//phone number field object  
        quitCmd = new Command("Quit", Command.EXIT, 0);//creating quit command object  
        contCmd = new Command("Continue", Command.OK, 0);//creating continue command object  
        welForm.append(welStr);//adding welcome string item to form  
        welForm.append(phoneField);//adding phone field to form  
        welForm.append(phoneError);//adding phone error string item to form  
        welForm.addCommand(contCmd);//adding continue command  
        welForm.addCommand(quitCmd);//adding quit command  


    //start application method definition  
    public void startApp() {  

    //pause application method definition  
    public void pauseApp() {  

    //destroy application method definition  
    public void destroyApp(boolean unconditional) {  

    //Command action method definition  
    public void commandAction(Command c, Displayable d) {  
        if (d == welForm) {  
            if (c == quitCmd) {  
                exitMidlet();//call to exit midlet  
            } else {//if the command is contCmd  
                //place a waiting activity indicator  
                System.out.println("ken de man");  
                Thread t = new Thread() {  

                    public void run() {  
                        try {  

                            //method to connect to server  

                        } catch (Exception e) {  
                        }//end of catch  
                    }//end of ru()  
                };//end of thread  
                t.start();//starting the thread  
            }//end of else  
        }//end of first if  

    }//end of command action  

    //defining method to exit midlet  
    public void exitMidlet() {  
    }//end of exitMidlet()  

    //defining sendPhone method  
    public void sendPhone() throws IOException {  

        System.out.println("ken de man");//check  

        HttpConnection http = null;//HttpConnection variable  
        OutputStream oStrm = null;//OutputStream variable  
        InputStream iStrm = null;//InputStream variable  
        String url = "http://localhost:8084/MvsWeb/CheckPhone";//server url  

        try {  
            http = (HttpConnection) Connector.open(url);//opening connection  
            System.out.println("connection made");//checking code  
            oStrm = http.openOutputStream();//opening output stream  
            http.setRequestMethod(HttpConnection.POST);//setting request type  
            http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//setting content type  
            byte data[] = ("phone=" + phoneField.getString()).getBytes();  
            iStrm = http.openInputStream();//openning input stream  
            if (http.getResponseCode() == HttpConnection.HTTP_OK) {  
                int length = (int) http.getLength();  
                String str;  
                if (length != -1) {  
                    byte servletData[] = new byte[length];  
                    str = new String(servletData);  
                } else // Length not available...  
                    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();  

                    int ch;  
                    while ((ch = iStrm.read()) != -1) {  

                    str = new String(bStrm.toByteArray());  
                System.out.println("de man");  


                if (str.equals("ok")) {  
                    //change to vcode form  

                } else {  
                    //add error message to phone_error stingItem  
        } catch (Exception e) {  
}//end of class definition  

import java.io.*;//package for io classes  
import javax.servlet.ServletException;//package for servlet exception classes  
import javax.servlet.http.*;  
import java.sql.*;//package for sql classes  

 * @author k'owino 
public class CheckPhone extends HttpServlet {  

    protected void doGet(HttpServletRequest req, HttpServletResponse res)  
    throws ServletException, IOException {  


    protected void doPost(HttpServletRequest req, HttpServletResponse res)  
    throws ServletException, IOException {  

        //declaring variables  
        PrintWriter pw;//PrintWriter object  
        String pnum;//phone parameter sent from client  
        Connection con = null;//connection variable  
        String dbDriver = "com.jdbc.mysql.Driver";//the database driver  
        String dbUrl = "jdbc:mysql://localhost/mvs_db";//the database url  
        String dbUser = "root";//database user  
        String dbPwd = "";//database password  
        PreparedStatement pstmt = null;//Prepared statement variable  
        String query = "select * from student where stud_phone = ?;";  
        ResultSet rs = null;//resultset variable  
        String dbPhone=null;//phone from database  

        //getting the "phone" parameter sent from client  
        pnum = req.getParameter("phone");//getting the "phone" parameter sent from client  

        //setting the content type of the response  

        //creating a PrintWriter object  
        pw = res.getWriter();  

        try{//trying to load the database driver and establish a connection to the database  

            Class.forName(dbDriver).newInstance();//loading the database driver  
            con = DriverManager.getConnection(dbUrl,dbUser,dbPwd);//establishing a connection to the database  
            System.out.println("connection established");  
        catch(Exception e){  


        //trying to query the database  

            pstmt = con.prepareStatement(query);//preparing a statement  
            pstmt.setString(1, pnum);//setting the input parameter  
            rs = pstmt.executeQuery();//executing the query assigning to the resultset object  

            //extracring data from the resultset  
                dbPhone = rs.getString("stud_phone");//getting the phone number from database  
            }//end of while  


        catch(Exception e){  



    public String getServletInfo() {  
        return "Short description";  
    }// </editor-fold>