×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    Sending image to Servlet problem

    Hi, I want to send an Image to Servlet and get the same Image back from servlet and display it. ...thats what my need is.


    String url="http://localhost:8080/Kenbook/a";
    GPRSConnection gprsConnection=new GPRSConnection(url);
    gprsConnection.setParam("image", img.toString());
    gprsConnection.start();

    -----------------------------------------------------------------------------------------------------------------------------------

    private void makeConnectionWithServer() {
    try{

    httpConnection=(HttpConnection)Connector.open(url,Connector.WRITE);
    httpConnection.setRequestMethod(HttpConnection.POST);
    httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    httpConnection.setRequestProperty("Connection", "keep-alive");
    httpConnection.setRequestProperty("Content-Length", Integer.toString(bufferOfPostParameter.toString().length()));


    }catch(Exception e){
    System.out.println("ERROR IN CONNECTION :"+e.getMessage());
    e.printStackTrace();
    }
    }





    private void sendDataToServer() {
    try {
    outputStream=httpConnection.openOutputStream();
    outputStream.write(bufferOfPostParameter.toString().getBytes());

    if(httpConnection.getResponseCode()!=HttpConnection.HTTP_OK){
    throw new RuntimeException("SERVER NOT ACCEPTING CONNECTION :"+httpConnection.getResponseCode());
    }
    } catch (Exception e) {
    Log("Error in Sending Data");
    e.printStackTrace();
    }
    }



    private InputStream getDataFromServer() {
    try {
    is=httpConnection.openInputStream();

    return is;


    } catch (Exception e) {
    Log("Error in getting Data From Server "+e.getMessage());
    e.printStackTrace();
    return null;
    }
    }




    public void run() {
    try {
    makeConnectionWithServer();
    sendDataToServer();
    InputStream is = getDataFromServer();




    Form f=new Form("sss");
    System.out.println("VALUE OS :"+is);
    Image img=Image.createImage(is);
    f.append(img);
    MyFileMidlet.d.setCurrent(f);
    } catch (Exception e) {
    e.printStackTrace();
    }

    }




    I am not getting the result....plz help me where i am going wrong...

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Sending image to Servlet problem

    some things are missing here.
    what are those 4 first lines?
    this
    gprsConnection.setParam("image", img.toString());
    is probably not what you want to do.
    what kind of error do you get?

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Re: Sending image to Servlet problem

    hi,
    you can use http multipart to post files to servers.
    The below link is for http multipart post.
    http://wiki.forum.nokia.com/index.ph...oad_in_Java_ME
    thankx

Similar Threads

  1. Problems on sending data to Servlet
    By OrlandoBarrera in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2010-06-14, 21:02
  2. Sending Data from MIDlet to Servlet
    By kai_buki in forum Mobile Java Networking & Messaging & Security
    Replies: 13
    Last Post: 2009-05-21, 10:03
  3. Sending a image from midlet to a servlet. Help on recoding image.
    By Kaisser in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2008-10-06, 15:45
  4. Sending MMS from Servlet?
    By Marco204 in forum General Messaging
    Replies: 1
    Last Post: 2005-10-20, 07:03
  5. Servlet sending 3gp to nokia
    By vmoreno1972 in forum Streaming and Video
    Replies: 6
    Last Post: 2004-04-01, 09:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×