Hi ,
ich habe schon wieder eine Frage.
Ich habe eine Klasse Cookie, mit der man Cookies setzen und lesen kann - mittels PHP
Das geht auch soweit.
- Wenn kein Cookie gesetzt ist, dann gibt mir php "notSet" zurück.
- Java bekommt das auch, aber bei der Abfrage, ob mein Java String "data" "notSet" ist, überspringt er einfach. :bahnhof:
Code meines Applets:
Code der Cookie-Klasse:
Ich verstehe das nicht ganz - er gibt mir ja auch "notSet" in der Konsole aus
Lg
Tino
ich habe schon wieder eine Frage.
Ich habe eine Klasse Cookie, mit der man Cookies setzen und lesen kann - mittels PHP
Das geht auch soweit.
- Wenn kein Cookie gesetzt ist, dann gibt mir php "notSet" zurück.
- Java bekommt das auch, aber bei der Abfrage, ob mein Java String "data" "notSet" ist, überspringt er einfach. :bahnhof:
Code meines Applets:
Code:
Cookie c = new Cookie("http://www.meineURL/cookie.php");
try {
String data = c.getCookie().trim();
while (c.hasData() == false) {
System.out.println("warte auf cookie...");
};
if (data == "notSet") {
loginName.setText("Username");
loginPass.setText("Passwort");
System.out.println("Kein Cookie vorhanden");
}
} catch (IOException e1) {}
Code der Cookie-Klasse:
Code:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class Cookie {
private URL url;
private HttpURLConnection urlc;
private InputStream is;
private String data = null;
public Cookie(String link) {
try {
this.url = new URL(link);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public String getCookie() throws IOException {
try {
urlc = (HttpURLConnection)url.openConnection();
urlc.setRequestMethod("POST");
urlc.setUseCaches(false);
is = urlc.getInputStream();
} catch (IOException e) {e.printStackTrace();}
int c = 0;
StringBuffer incoming = new StringBuffer();
while (c >= 0) {
c = is.read();
incoming.append((char) c);
}
data = incoming.toString().substring(0,incoming.toString().length()-1);
return (data);
}
public void send(String data) throws IOException {
if (urlc == null) {
urlc = (HttpURLConnection)url.openConnection();
}
if (urlc.getDoOutput() == false) {
urlc.setDoOutput(true);
}
OutputStream out = urlc.getOutputStream();
out.write(data.getBytes());
out.flush();
}
public boolean hasData() {
if (data != null) {
return true;
} else {
return false;
}
}
}
Ich verstehe das nicht ganz - er gibt mir ja auch "notSet" in der Konsole aus
Lg
Tino