• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet CGI communication - Please help!?

 
Mahesh Srinivasan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have set up a java applet for my group�s website and am trying to figure out how to send applet data (write a file) to the server. I have written a cgi script which takes a string and writes it to a file, and I know that this script functions properly since it works when I run it in the console.
Essentially, the problem is that in order to access the cgi program, I have to connect a URL beginning with: http://cgi.stanford.edu..... This is a problem because java�s security restrictions only allow you to send data to programs originating from the same code base (e.g. http://www.stanford.edu). So when I try to send data to http://cgi.stanford.edu/group.... an exception is raised called an "access control exception" from the following code:

public void SendData(String data) {

try {
URL url = new URL("http", "cgi.stanford.edu/group/languagelab", "/cgi-bin/write.cgi");
URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.connect();
con.setRequestProperty("Content-type", "text/plain");
con.setRequestProperty("Content-length", data.length()+"");
PrintStream out =
new PrintStream(con.getOutputStream(), true);
out.println(data);
out.close();

DataInputStream in =
new DataInputStream(con.getInputStream());
String s;
while ((s = in.readUTF()) != null) {
}
in.close();
}

catch (MalformedURLException mue) {
getAppletContext().showStatus("MalformedURLException"+mue.toString());
}
catch (IOException ioe) {
getAppletContext().showStatus("IOexception"+ioe.toString());
}

catch (Exception e) {
getAppletContext().showStatus("exception"+e.toString());
}
}


Do you have any idea how I can fix this problem, or know anyone that could possibly help? I would be very grateful if you could help.

Thanks a lot,
Mahesh
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic