2 Replies Latest reply on Sep 7, 2011 2:09 PM by 886023

    Servlet to upload file from J2ME midlet

      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.
        • 1. Re: Servlet to upload file from J2ME midlet
          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
            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].


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