Results 1 to 2 of 2
- 05-27-2010, 04:40 PM #1
Member
- Join Date
- May 2010
- Posts
- 47
- Rep Power
- 0
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
ThanksJava 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); } }Last edited by Basit781; 05-27-2010 at 04:46 PM.
- 05-31-2010, 08:46 AM #2
Member
- Join Date
- May 2010
- Posts
- 47
- Rep Power
- 0
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.
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.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(); }
Thank you.
Similar Threads
-
[SOLVED] Display the text.log file in the browser
By jazz2k8 in forum Advanced JavaReplies: 2Last Post: 06-09-2009, 02:23 PM -
Can't display web application in my browser
By gissah in forum NetBeansReplies: 0Last Post: 03-18-2009, 03:19 AM -
Display MS-Word file in browser
By jazz2k8 in forum Advanced JavaReplies: 6Last Post: 12-08-2008, 12:59 PM -
Display available ImageReaders and ImageWriters by image format and MIME type
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:25 PM -
Date format display in CSV file after exporting
By latha in forum Advanced JavaReplies: 0Last Post: 08-03-2007, 08:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks