I have modified the login in and implemented this instead.
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();
}
}
}
The response from the url on debugging gave a right answer that the login was successfull i.e in the commandline. But I noticed that the string comparison doesn’t return a correct logic
i.e
if (getS.substring(0, 16).equals(msg)){
System.out.println(getS);
switchDisplayable(null, svgMenu.getSvgCanvas());
}
The if statement never gets to execute. What do I do.
You made a mistake on server side. Because you sending the string value of username and password from client side(mobile). you need to validate on server side. Before that you need to check if any white space on username and password on client side(mobile). use
getUsername().getString().trim()andgetPass().getString().trim()and also If need check the case sensitive.