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