String 使用J2me从WML页面获取数据
我在j2me中有一个程序,可以从wml/asp页面获取字符串和数据。String 使用J2me从WML页面获取数据,string,java-me,midp,lcdui,String,Java Me,Midp,Lcdui,我在j2me中有一个程序,可以从wml/asp页面获取字符串和数据。 使用此代码: HttpConnection con = (HttpConnection) Connector.open( "http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester); DataInputStr
使用此代码:
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);
当我的j2me应用程序尝试读取和存储此页面中的数据时:
"http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester
放置在名为(result)的字符串中的文本与下图所示的内容完全不同:
它采用的内容没有格式,如下所示:
<!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>
如何让我的j2me将字符串视为原始格式化页面?我解决了这个问题,特别是在j2me中没有(拆分方法)这一点有点棘手 所以我简单地创造了一个 我把它擦掉了
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;
}
String[]拆分(字符串x){
int num=0;
对于(int i=0;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;
}
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());