PDA

View Full Version : Java Applet connecting to URL


barrett777
03-15-2006, 03:56 AM
Hi All,

I have a Java Applet, and I want it to connect to a .CGI file. I've done this before and everything worked fine. This time around I'm having problems. Here's my code:

public boolean save()
{
boolean saveSuccessful = false;

String data = "Test";

String serverMessage = "";

try
{
URLConnection urlConnection = new URL("http://www.bearandkitten.com/cgi-bin/save.cgi").openConnection();
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-type", "text/plain");
urlConnection.setRequestProperty("Content-length", data.length()+"");
PrintStream out = new PrintStream(urlConnection.getOutputStream());
out.print(playerData);
out.flush();
out.close();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String stringTemp;
while((stringTemp = bufferedReader.readLine()) != null) serverMessage = serverMessage.concat(stringTemp + " ");
if(serverMessage.equals("SAVE")) saveSuccessful = true;
}
catch(Exception e){}

return saveSuccessful;
}

When I run this, an exception isn't called, but I don't get any of the messages that I print in my .CGI application. Is this a server config problem? Or a problem with my .CGI? Or is there a problem in my Java code? My applet is stored in the base directory (for now), at http://www.bearandkitten.com.

Thanks for your time,
Ben

barrett777
03-16-2006, 09:35 PM
Alright, I've figured out my mistakes, this question isn't needed anymore.:)