Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 40
Registered: ‎07-20-2010
My Device: Not Specified

sending data from application to a web form



I am trying to store data from my application to a mysql database on the web. To do this, I have created a php based web form which is able to transfer data to the mysql database and am trying to send the data from my app to the web form.


the web form is located at -



the application code is -


    public void run(){
        try {
            HttpConnection connection = (HttpConnection)Connector.open(url);
            int responseCode = connection.getResponseCode();
                screen.requestFailed("failed to create connection: " + responseCode);

                String data = "data to be posted";
                byte[] postData = data.getBytes();
                screen.requestFailed("converted data to bytes");
                connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
                OutputStream requestOutput = connection.openOutputStream();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            screen.requestFailed("failed: " + e.toString());



I think I am able to create the http connection but I have no idea how to transfer data from the application to each of the input boxes in the form.


Can anyone please help ?



Regular Contributor
Posts: 98
Registered: ‎08-31-2010
My Device: BB-9700
My Carrier: Airtel

Re: sending data from application to a web form

You can implement intoerfaces for HTTPCommunication class. The class where you want the response data back, need to implement those interfaces. You can actually pass the data object as a parameter to call back.


Once you get call back into the implemented method you can use SetText method of the text box to be filled with corresponding values.


Sorry if i misunderstood your questions.






Posts: 40
Registered: ‎07-20-2010
My Device: Not Specified

Re: sending data from application to a web form


Hi Abhijit,


I am trying to send data to the form and not recieve data from the form.



Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: sending data from application to a web form

Apologies, I don't have the time to go into depth right now, here is a quick summary to get you going.


Your Web form is doing a post to the URL specified in the action.  The form will have a number of ids that it sets, the URl specified in the action will pick up the values of these ids.  So this is the process you heed to replicate.


You do this by writing the ids and data into the request.  Here is some sample code, which has the ids

userName, and



Hope this makes sense and you can use it.  Do a search for POST in this forum for other samples.


HttpConnection connection = (HttpConnection)Connector.open(url);
//Above as before
URLEncodedPostData postData = new URLEncodedPostData("", false);
postData.append("userName", email);
postData.append("userPwd", pwd);
byte[] postDataBytes = postData.getBytes();
connection.setRequestProperty("Content-Length", (new Integer(postDataBytes.length)).toString());
OutputStream os = connection.openOutputStream();
// Following as before
int responseCode = connection.getResponseCode();