我正在尝试通过使用页面在通过 java 获取页面内容时给我的结果来在 java 中创建登录系统,就像我从获取数据时一样
http://localhost/java.php?un=dubking&password=password
当登录凭据正确时,该页面只会将“true”显示为 html,但是当我使用包含来自该页面的数据的数组时,在 if 语句中实际上包含“true”时,if 语句不起作用,是我做错了什么,或者这在 Java 中是不可能的吗?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
class test2 {
public void calc() {
try {
URL yahoo = new URL("http://localhost/java.php?un=" + username + "&password=" + password);
BufferedReader in = new BufferedReader(
new InputStreamReader(yahoo.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
// Process each line.
String html = inputLine;
if (html == "true") {
System.out.print("You have successfully logged in.");
} else {
if (html == "false") {
System.out.println("Wrong username or password.");
}
if (html != "true" && html != "false") {
System.out.println("something went wrong.");
System.out.println(html);
}
}
}
in.close();
} catch (MalformedURLException me) {
System.out.println(me);
} catch (IOException ioe) {
System.out.println(ioe);
}
}
}