This discussion is archived
2 Replies Latest reply: Sep 7, 2011 7:09 AM by 886023 RSS

Servlet to upload file from J2ME midlet

865121 Newbie
Currently Being Moderated
Does anybody know how to do a java servlet to upload a file sent from a J2ME midlet application?
I have to upload a file to a http server from my J2ME application. For this, I use HttpConnection in J2ME to open an url and the POST method to send the bytes, but I don't know how to save the file on the server side, and for this I think I need a java servlet, but I don't know how to do it.
Thanks!
  • 1. Re: Servlet to upload file from J2ME midlet
    799151 Explorer
    Currently Being Moderated
    It's very simple.

    When the request comes to the servlet use HttpServletRequest's getInputStream() method to gain access to the incoming data. Then, copy the data from IntpuStream to some OutputStream (in your case it'll be probably FileOutputStream - see the javadoc) and finally close the streams. You can also send a response to midlet.

    This is written very general, if You face a particular problem ask conrete question.
  • 2. Re: Servlet to upload file from J2ME midlet
    886023 Newbie
    Currently Being Moderated
    The upload request must comply to RFC1867 (see [url http://www.ietf.org/rfc/rfc1867.txt] ). The servlet must parse this request with Apache Commons FileUpload. You can find an example of a servlet with Commons FileUpload here: [url http://www.javaatwork.com/java-upload-applet/samplecode.html#servlet].

    Johannes

    Edited by: 883020 on Sep 7, 2011 7:03 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points