AccessDenied with Integrated Applet

Hi.

I've visited a lot of topics about this subject but I can't find a answer that englobes all my problems...

So... Here's what I need...

I need to build a Applet that will be acessed by HTML on a server... For example http://localhost/HTMLView.html...

In that Applet I need to put the content of html files present in the same server... For example: I need to put in a JEditorPane the content of http://localhost/testpage.html...

Everytime I open a html file for streaming it returns me an AccessDenied Exception...

If I edit my java.policy file and allow Secury.AllPermission everything works fine..

So... Anyone have a suggestion to me?

Tanks

[704 byte] By [c00jz3r0a] at [2007-10-1 7:28:32]
# 1

OK, applet is here:

http://myServer/myAppletts/myApplet.jar

The html file doesn't provide a codebase value for the applet and I need to edit a file here:

http://myServer/myHtmlTextFilesInUTF-8/myHtmlfile.html

// To read that file you can use the URL object:

URL u = new URL(this.getCodeBase(),"../myHtmlTextFilesInUTF-8/myHtmlfile.html"

// Open a urlconnection:

URLConnection c = u.openConnection();

InputStream in = c.getInputStream();

// read the file

ByteArrayOutputStream bos = new ByteArrayOutputStream();

byte[] buf = new byte[1024];

int len;

while ((len = in.read(buf)) > 0) {

bos.write(buf, 0, len);

}

byte[] data = bos.toByteArray();

// create a string of the file

String theHTMLFile = new String(data,"UTF-8");

Remember: applets cannot access the local filesystem nor can they connect with any

other server than the one thy came from. To save the file you can use URL and

URLConnection to POST the data to a servlet and let the servlet write it to disc.

harmmeijera at 2007-7-9 18:48:26 > top of Java-index,Security,Signed Applets...
# 2

Ok. Thanks. That works!

>To save the

> file you can use URL and

> URLConnection to POST the data to a servlet and let

> the servlet write it to disc.

Can you give me more details about how that process works? I mean... How the servlet works and how I post data to it...

Thanks

c00jz3r0a at 2007-7-9 18:48:26 > top of Java-index,Security,Signed Applets...
# 3

Assuming you have only text to send with the applet in a way that a html form would send textarea

<form method="post" enctype="application/x-form-urlencoded">

<textarea id="contentOfMyFile" name="contentOfMyFile">

This is the content of my file

</textarea>

</form>

you could check out the following site:

http://javaalmanac.com/cgi-bin/search/find.pl?words=post+url

Both URL (applet) and servlet example are there.

harmmeijera at 2007-7-9 18:48:26 > top of Java-index,Security,Signed Applets...