0
我修改了登录并实施了此操作。在我的midlet中验证用户名和密码的问题
public void login() {
HttpConnection c = null;
InputStream is = null;
StringBuffer str = new StringBuffer();
String url = "http://101.00.00.000/...../"
+ "?user=" + getUsername().getString().trim()
+ "&password=" + getPass().getString().trim();
try {
c = (HttpConnection) Connector.open(url);
is = c.openInputStream();
int len = (int)c.getLength();
int ch;
String getS = "";
while((ch = is.read()) != -1){
str.append((char)ch);
getS = str.toString();
String msg = "Login successful";
System.out.println(getS.substring(0, getS.length()));
if (getS.substring(0, 16).equals(msg)){
System.out.println(getS);
switchDisplayable(null, svgMenu.getSvgCanvas());
}else{
switchDisplayable(null, getAlert2());
// }
}
System.out.println(getS);
}
catch (IOException exception) {
try {
if (is != null)
is.close();
if (c != null)
c.close();
exception.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
url对调试的响应给出了正确的答案,即登录是成功的,即在命令行中。但我注意到,字符串比较不返回正确的逻辑 即
if (getS.substring(0, 16).equals(msg)){
System.out.println(getS);
switchDisplayable(null, svgMenu.getSvgCanvas());
}
的if语句永远不会执行。我该怎么办。
你在服务器端检查过吗? – bharath
服务器端是正确的。我在j2se中实现了一个类似的应用程序,它运行良好 – nnanna
你从服务器端得到了什么回应? – bharath