Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

This has to be a security issue

  Asked By: Hamish    Date: Apr 20    Category: Java    Views: 490

but it's been one that's bothered me off and on for months. I've
been trying to write an applet to establish a remote connection and
retrieve data. Simple, right? And it's been done before, I'm sure.
But I can't get the darned thing to work on a Web server, local or
otherwise. Here's the relevant code, minus the comments. Please
excuse the temporary hardcoding of a URL.

public void RequestXML(String path, String query)
throws java.net.MalformedURLException, java.io.IOException

URL dURL=new URL("http://localhost/test/planetdata.php");
URLConnection conn=dURL.openConnection();
BufferedReader in=new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
String xmldata="";
while ( (line=in.readLine())!=null )
root = new Xparse().parse(xmldata);

Naturally, the whole applet works perfectly in the debugger, but when
I try to embed it in a Web page, I always get via JavaScript:
"Error: uncaught exception: java.security.PrivilegedActionException:
when I try to invoke the RequestXML method. I believe this occurs at
the getInputStream() call. Sounds like the applet doesn't have
permission to access the file, but shouldn't it? Running from a
server where the file is in the same directory as the applet?

As I've said, I've struggled with this off and on for months, and am
getting fairly pissed off over it. And of course all the Java
documentation is about as clear as 47 feet of crude oil.

Any help?



3 Answers Found

Answer #1    Answered By: Gilberto Thompson     Answered On: Apr 20

Can't explain it, but it's working perfectly now. Local, remote, any
browser. ? Didn't change that part of the code. Software, as
we all know, is very much akin to magic, except that magic is easier
to understand, and often much more reliable.

Answer #2    Answered By: Abbas Hashmi     Answered On: Apr 20

did u make any change to the url? (http://localhost/test/planetdata.php)
or any security  policy?
I'm not sure, but as I remembered, applet  can't access url  other than url
within its server.

Answer #3    Answered By: Jana Franklin     Answered On: Apr 20

That's correct. A applet  can only access files from the directory it
was loaded from or a subdirectory thereof. But I know the files were
in the right place. Must have fixed something, but I sure can't
figure out what it was.

Didn't find what you were looking for? Find more on This has to be a security issue Or get search suggestion and latest updates.