2012-04-28 15 views
2

私は、wml/aspページから文字列とデータを取得するプログラムをj2meに用意しています。私のJ2MEアプリケーションは、このページからデータを読み込み、保存しようとするとJ2MEを使用してWMLページからデータを取得

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); 

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

(結果)と呼ばれる文字列に配置されたテキストは、同様の何物でもありません。このコードを使用して

The Page called

:以下の図に期待

それは以下のようにフォーマットせずにコンテンツを取っている:

<!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> 

を私はStringItemのにこのテキストを割り当てたときに、それは図2のように下に示しています。私のJ2MEは、元のフォーマットされたページとして文字列を表示するために取得できますか

stringItem2.setText(result); 

enter image description here

答えて

1

私はそれを解決しましたが、それは特にj2meには(分割方法)が少し難解でした。

私は単純に作成しました。

Iは

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; 
     } 

をdeclearedし、私はそれを適用し、リスト内の結果

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()); 

を表示し、結果は以下のようにより完全なソースコードなし(行単位)たかったです。 wmlページ。

enter image description here

関連する問題