tags:

views:

96

answers:

0

Actually i finished the code to read the content in side "http://localhost:8080/outpuu.xml".,, it works fine while downloading the content from that url. but while i trying to update the content, I'm doing following.,

  • open http connection
  • set request property
  • open output stream
  • write the content to that output stream

but it didn't throw any exception or error., but still that file content is not updated.,, this is my actual code.,,


import javax.microedition.midlet.; import javax.microedition.lcdui.; import javax.microedition.io.; import java.io.; public class UploadMidlet extends MIDlet implements Runnable, CommandListener{ private final String FILE = "This is the image text that to be written in the given file"; private final String URL = "http://localhost:8080/output.xml"; // change this to a valit page. private final String CrLf = "\r\n"; private Form form = null; private Gauge gauge = null; private Command exitCommand; private Command uploadCommand; public UploadMidlet(){ form = new Form("Upload File"); gauge = new Gauge("Progress:", true, 100, 0); form.append(gauge); exitCommand = new Command("Exit", Command.EXIT, 0); uploadCommand = new Command("Upload", Command.SCREEN, 0); form.addCommand(exitCommand); form.addCommand(uploadCommand); form.setCommandListener(this); } public void startApp() { Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void run() { httpConn(); } private void httpConn(){ HttpConnection conn = null; OutputStream os = null; InputStream is = null; try{ System.out.println("url:" + URL); conn = (HttpConnection)Connector.open(URL,Connector.WRITE); conn.setRequestMethod(HttpConnection.POST); String message1 = ""; message1 += "-----------------------------4664151417711" + CrLf; message1 += "Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"" + "hi how are you" + "\"" + CrLf; message1 += "Content-Type: html/text" + CrLf; message1 += CrLf; // the image is sent between the messages ni the multipart message. String message2 = ""; message2 += CrLf + "-----------------------------4664151417711--" + CrLf; conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711"); // might not need to specify the content-length when sending chunked data. // conn.setRequestProperty("Content-Length", String.valueOf((message1.length() + message2.length() + imgData.length))); System.out.println("open os"); os = conn.openOutputStream(); System.out.println(message1); os.write(message1.getBytes()); System.out.println(" "+conn.getResponseCode()); System.out.println("DONE"); }catch(Exception e){ e.printStackTrace(); }finally{ System.out.println("Close connection"); try{ os.close(); }catch(Exception e){} try{ is.close(); }catch(Exception e){} try{ conn.close(); }catch(Exception e){} } } public void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable) { if(command == exitCommand){ this.notifyDestroyed(); }else if(command == uploadCommand){ new Thread(this).start(); } } }


Would anyone help me?.,,