Discussion Board

Results 1 to 3 of 3

Thread: HTML Tags

  1. #1
    Registered User
    Join Date
    Aug 2008

    HTML Tags

    When I run http-connection on S60 emulator, the result page will be displayed as HTML tags not a real web page. Do I need to install another software on the S60 or my code need to be changed. Here is the code (code copied from another forum for test):
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import java.io.*;
    public class HttpPOST extends MIDlet implements CommandListener 
      // A default URL is used. User can change it from the GUI.
      private static String defaultURL = "http://www.google.com";
      // GUI component for entering a Web URL
      private Display myDisplay = null;
      private Form mainScreen;
      private TextField requestField;
      // GUI component for displaying server responses.
      private Form resultScreen;
      private StringItem resultField;
      // the "send" button used on mainScreen
      Command sendCommand = new Command("SEND", Command.OK, 1);
      // the "back" button used on resultScreen
      Command backCommand = new Command("BACK", Command.OK, 1);
      public HttpPOST()
        // initialize the GUI components
        myDisplay = Display.getDisplay(this);
        mainScreen = new Form("Type in a URL:");
        requestField = new TextField(null, defaultURL, 100, TextField.URL);
      public void startApp() 
      public void pauseApp() { }
      public void destroyApp(boolean unconditional) 
        // help Garbage Collector
        Display myDisplay = null;
        mainScreen = null;
        requestField = null;
        resultScreen = null;
        resultField = null;
      public void commandAction(Command c, Displayable s) 
        // when user clicks on the "send" button
        if (c == sendCommand) 
          GetResponse t = new GetResponse ();
        else if (c == backCommand) 
          // do it all over again
       class GetResponse extends Thread
          private CommandListener listener;
          public void setListener(CommandListener cl)
             listener = cl;
          public void run()
             // retrieve the Web URL that user entered
             String urlstring = requestField.getString();
             // send a POST request to Web server
             String resultstring = "";
               resultstring = sendPostRequest(urlstring);
             catch (IOException e) 
               resultstring = "ERROR";
             // display the message received from Web server
             resultScreen = new Form("POST Result:");
             resultField = new StringItem(null, resultstring);
             resultScreen.append(defaultURL + "\n");
      // send a POST request to Web server
      public String sendPostRequest(String urlstring) throws IOException 
        HttpConnection hc = null;
        DataInputStream dis = null;
        DataOutputStream dos = null;
        String message = "";
        // the request body
        String requeststring = "i=QL";
          // an HttpConnection with both read and write access
          hc = (HttpConnection)Connector.open(urlstring, Connector.READ_WRITE);
          // set the request method to POST
          //Send header information for POSt to work
          //i m getting NullPointerException here.
          //hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          // obtain DataOutputStream for sending the request string
          dos = hc.openDataOutputStream();
          byte[] request_body = requeststring.getBytes();
          // send request string to Web server
          for (int i = 0; i < request_body.length; i++) 
          // flush it out
          // obtain DataInputStream for receiving server responses
          dis = new DataInputStream(hc.openInputStream());
          // retrieve the responses from Web server
          if (hc.getResponseCode() == HttpConnection.HTTP_OK)
             System.out.println("Response is ok.");
          int ch;
          while ((ch = dis.read()) != -1) 
            message = message + (char) ch;        
          // free up i/o streams and http connection
          if (hc != null) hc.close();
          if (dis != null) dis.close();
          if (dos != null) dos.close();
        return message;

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2003
    USA, CA

    Re: HTML Tags

    There is no HTML rendering engine in MIDP (unless you build it yourself or use an engine built by someone else...and I do not know of any open source package for that).

    You need to display the page with the phone browser. Use platformRequest(<url>) for that.


  3. #3
    Regular Contributor
    Join Date
    Jun 2008

    Re: HTML Tags

    In the past there was : http://www.reqwireless.com/
    They Had an Open Source API for Parsing HTML.
    Nowadays, Google bought them for their new future development based over mobile...

    Try Digging over the web(very very deeply) in case there is any other....

Similar Threads

  1. query-string in html files
    By yalabik in forum Mobile Web Site Development
    Replies: 7
    Last Post: 2007-12-16, 17:55
  2. Remove HTML tags from XML parsed text
    By sandro1972 in forum Mobile Java General
    Replies: 1
    Last Post: 2007-12-14, 10:13
  3. Replies: 1
    Last Post: 2007-05-16, 15:03
  4. html tags with midp2
    By kmsoomro in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-19, 19:11
  5. html tags
    By kmsoomro in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-05, 12:31

Posting Permissions

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