Question

I have a program in j2me that get strings and data from an wml/asp page.
Using this code:

HttpConnection con = (HttpConnection) Connector.open(
    "http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester);
DataInputStream in = new DataInputStrea(con.openInputStream());
int len = (int) con.getLength();
byte[] info = new byte[len];
in.readFully(info);
result = new String(info);

switchDisplayable(null, getStudentCourses());
stringItem2.setText(result);

When my j2me application try to read and store the data from this page:

"http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester

the text which is placed in the string called (result) is nothing similar to expected figure below:

The Page called

It's taking the content without formatting as below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



 <wml>
 <card>
 <p><b>Student Name :</b> Arin                 Rizk                </p>
 <p><b>Student ID</b> : 20111</p>
 <p>first Semester ,2011</p>
 1 - Course Name : DDD        | Credits Number : 3          | Mark : 70         </br>  2 - Course Name : EEE        | Credits Number : 3          | Mark : 65         </br>  3 - Course Name : EEE        | Credits Number : 3          | Mark : 65         </br>  4 - Course Name : EEE        | Credits Number : 3          | Mark : 90         </br>  
 </card>
 </wml>

so when I assigned this text to the StringItem it's showing as below in the fig.

stringItem2.setText(result);

enter image description here

How can get my j2me to view the strings as the original formatted page?

Was it helpful?

Solution

I solved it , it was a little bit tricky specially that in j2me there is no (split method) .

so simply I created one.

I decleared it

String[] split (String x){
        int num=0;
        for(int i=0; i<x.length(); i++)  // count the number of ','
            if(x.charAt(i)==',')
                num++;

        String[] r=new String[num];
        for(int i=0; i<num; i++)
        {
            int loc=x.indexOf(",");  //loc is the location of each ','
            r[i]=x.substring(0,loc);
            x=x.substring(loc+1);
        }
            return r;
        }

and then I applied it and display the results in a list

HttpConnection con = (HttpConnection) Connector.open("http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester);
                            DataInputStream in = new DataInputStream(con.openInputStream());
                            int len = (int) con.getLength();
                            byte[] info = new byte[len];
                            in.read(info);
                            result = new String(info);                          
                            String[] a=split(result);
                    getList().deleteAll();
                    for(int i=1; i<a.length; i++)
                        getList().append(a[i], null);

                    switchDisplayable(null,getList());

and the results were as wanted ( in rows ) without the full source code from the wml page.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top