Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with URL -> Applet

 
Ardi Hundt
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i have a little problem running my applet. it's supposed to get a file from the WWW and display its contents as a string inside a JTextArea. the file on the web is a simple .txt containing little text, say one sentence, its irrelevant here. the file is read in inside a different class that the applet calls. however, there seems to be a problem with that - maybe it has something to do with Applet restrictions. anyway. here goes:

the applet (i removed all irrelevant applet construction objects like buttons etc) -

public class Applet1 extends JApplet {

private JTextArea sisestaJutt;
private String juttVeebist;

public void init() {

URLReader veebist = new URLReader();

try {
juttVeebist.equals( veebist.reader());
}
catch(Exception e) {
}

Container sisu = new Container();
sisestaJutt = new JTextArea(juttVeebist);
sisu = getContentPane();
sisu.setLayout( new BorderLayout() );
sisestaJutt.setBorder(brdr);
sisu.add(sisestaJutt, BorderLayout.CENTER);

}

}


the called class (& method) -

public class URLReader {
public static String reader()

throws Exception {

URL jjstreet = new URL("http://www.anydomain.com/file.txt");
BufferedReader input = new BufferedReader(
new InputStreamReader(
jjstreet.openStream()));

String inputLine = input.readLine();

input.close();

return inputLine;


}
}
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch Ardi.
I'm moving your question to Applets forum, folks there may help you.
Please continue your discussion here
 
Joe Ess
Bartender
Posts: 9338
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applet Security FAQ:

1. What are applets prevented from doing?
In general, applets loaded over the net are prevented from reading and writing files on the client file system, and from making network connections except to the originating host.

So if the text file is on a server other than the one you downloaded the applet from, you will get a security exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic