我嘗試使用結果頁面獲取網頁的內容時,對Java 喜歡當我從創建如果在Java中
http://localhost/java.php?un=dubking&password=password
獲取數據給我做Java中的登錄系統的URL內容聲明
當登錄憑據是正確的,該網頁將只顯示「真」爲HTML,但是當我使用該數據從該網頁實際上具有「真正」在其中的if語句的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);
}
}
}
這是什麼都用PHP做什麼? – PeeHaa
它可能會或可能不會工作。始終使用'「true」.equals(html)'而不是'=='運算符。 –
我不相信人們開始編碼,並留下這些簡單的概念O.o – anshulkatta