public void sendData(){
try {
URL data = new URL("http://mywebsite.net/isvalid.php?username=" + usernameField.getText() + "&password=" + passwordField.getText());
BufferedReader in = new BufferedReader(
new InputStreamReader(data.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
if(inputLine.length() > 0)
inputString = inputLine;
in.close();
if(!inputString.equals("Incorrect password.")){
System.out.println("Correct password");
run();
dispose();
} else
if(usernameField.getText().length() > 0 && passwordField.getText().length() > 0) {
invalidUP();
System.out.println("Invalid username or password.");
} else
if(usernameField.getText().length() < 1 || (passwordField.getText().length() < 1)) {
System.out.println("No password or username entered.");
upLength();
}
} catch (IOException e) {
e.printStackTrace();
}
}
我該如何檢查usernameField或passwordField是否有空格?如果有,請用「_」替換。替換java中的一個字符?
此外,如果您認爲此方法發送數據有誤或者可以更容易/更快地完成,請詳細說明。
看看String.replace – 2013-04-09 16:15:29
祕密是在[文檔](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html) – iamnotmaynard 2013-04-09 16:16:06
好吧,甜蜜。我已經使用替換方法,它的工作。有關方法本身的任何意見(sendData)? – user2192658 2013-04-09 16:58:31