Results 1 to 2 of 2
  1. #1
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Default What is the different between Text format display on web browser and display on midle

    Hi,
    Hope you all are fine. Can anyone tell me what is the difference between text format or decoding encodine technique display on windows web browser and inside midlet. Means when i run this link on desktop browser

    I get translation of "My name is basit" which is in UTF-8, In Uni code it's give me lot of numbers but when i run this link into my midilet i get garbage. why ?

    Here is the code that get value from CGi

    Java Code:
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    
    /**
     * An example MIDlet to invoke a CGI script (POST method is used).
     */
    
    public class InvokeCgiMidlet2 extends MIDlet {
    
       private Display display;
    
       //String url = "http://www.javacourses.com/cgi-bin/pgrade.cgi";
         //String url = "http://10.120.10.24/cgi-bin/http.cgi?cmd=baasit";
         
         String url = "http://10.120.10.31/cgi-bin/api/GT/GT_Send_Msg.cgi?message=My%20name%20is%20basit";
    
       public InvokeCgiMidlet2() {
          display = Display.getDisplay(this);
       }
    
       /**
        * Initialization. Invoked when we activate the MIDlet.
        */
       public void startApp() {
          try {
             getGrade(url);
          } catch (IOException e) {
             System.out.println("IOException " + e);
             e.printStackTrace();
          }
       }
    
       /**
        * Pause, discontinue ....
        */
       public void pauseApp() {
       }
    
       /**
        * Destroy must cleanup everything.
        */
       public void destroyApp(boolean unconditional) {
       }
    
       /**
        * Retrieve a grade....
        */
    
       void getGrade(String url) throws IOException {
          HttpConnection c = null;
          InputStream is = null;
          OutputStream os = null;
          StringBuffer b = new StringBuffer();
          TextBox t = null;
          try {
             c = (HttpConnection)Connector.open(url);
             c.setRequestMethod(HttpConnection.GET);
             c.setRequestProperty("CONTENT-TYPE","application/x-www-form-urlencoded");
             //c.setRequestProperty("CONTENT-TYPE","application/octet-stream");
             c.setRequestProperty("User-Agent","Profile/MIDP-2.1 Confirguration/CLDC-1.1");
            c.setRequestProperty("Content-Language", "en-UR");
             os = c.openOutputStream();
    
             // send input
            String str = "name=182016";
             byte postmsg[] = str.getBytes();
             for(int i=0;i<postmsg.length;i++) {
                 System.out.println("the value of Str is: " + postmsg[i] );
                os.write(postmsg[i]);
             }
             os.flush();
             is = c.openDataInputStream();
             int ch;
             // receive output
             while ((ch = is.read()) != -1) {
                b.append((char) ch);
                System.out.println((char)ch);
             }
             t = new TextBox("Final Grades", b.toString(), 1024, 0);
          } finally {
             if(is!= null) {
                is.close();
             }
             if(os != null) {
                os.close();
             }
             if(c != null) {
                c.close();
             }
          }
          display.setCurrent(t);
       }
    }
    Thanks
    Last edited by Basit781; 05-27-2010 at 05:46 PM.

  2. #2
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Default

    Hi,
    This problem is solved why garbage is coming from server because the data on server is in encoded in UTF-8, so when i used this function, it worked.

    Java Code:
     os = c.openOutputStream();
             /*
              String str = "?idnum=182016";
              byte postmsg[] = str.getBytes();
              for(int i=0;i<postmsg.length;i++) {
                os.writeByte(postmsg[i]);
              }
              os.flush();
              */
    
             Reader r = new InputStreamReader(c.openInputStream(), "UTF-8");
    
    
            // is = c.openDataInputStream();
    
             int ch;
             while ((ch = r.read()) != -1) {
                b.append((char) ch );
                System.out.println((char)ch);
             }
             txtArea2.setFocus(true);
             //txtArea2.setRTL(true);
             txtArea2.setText(b.reverse().toString().trim());
          } finally {
             if(is!= null) {
                is.close();
             }
    But i want to ask some thing. I am reading character, is it possible that i read whole string form the server not just character. I tried Bufferedreader but i think buffered reader is not supporter in java Me.Because what is happening right now it is showing character only. Actually the text that i am reading is in Urdu. So is there any way that i read the whole string not just charactrs.

    Thank you.

Similar Threads

  1. [SOLVED] Display the text.log file in the browser
    By jazz2k8 in forum Advanced Java
    Replies: 2
    Last Post: 06-09-2009, 03:23 PM
  2. Can't display web application in my browser
    By gissah in forum NetBeans
    Replies: 0
    Last Post: 03-18-2009, 04:19 AM
  3. Display MS-Word file in browser
    By jazz2k8 in forum Advanced Java
    Replies: 6
    Last Post: 12-08-2008, 01:59 PM
  4. Replies: 0
    Last Post: 06-24-2008, 12:25 AM
  5. Date format display in CSV file after exporting
    By latha in forum Advanced Java
    Replies: 0
    Last Post: 08-03-2007, 09:09 AM

Posting Permissions

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