• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need the "mantra" for an applet to write to temp

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I would be really greatful, if someone could tell me how to
let my applet write to C:\TEMP. I have gone thru numerous
discussions. All of them say "Give the right permissions.
Well, I have added the lines (as suggested in the Sun's Applet Security FAQ)
acl.read=c:\TEMP and
acl.write=c:\TEMP:c:\TEMP\iotest.log
to my hotjava\properties file. But can't get it to run.
Any help is greatly appreciated. The code follows.



[This message has been edited by Madhav Lakkapragada (edited March 06, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What I get when I run thru appletviewer or the browser is a well
known exception:

Thanks for your help.
regds.
- satya
 
Matt DeLacey
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhav,
Are you using appletviewer or IE or Netscape.
If you are using appletviewer, you can
achieve this without signing the applet.
One thing. Is c:\temp in your path?
Is the class that wants to write there
in your path. I can't remember exactly,
but one or the other or both needs to be.
If you are using IE or Netscape, the applet MUST be
signed. I've read various places that say you
can write to the server that loaded the applet
if it's not signed, but I've also read that you
can't, and I've spent many, many hours trying
with the same results as you are seeing. Everyone
agrees you can't write to the host without signing
the applet. If you want to write to the server
that loaded the applet you CAN make a proxy server
which takes a string or byte stream or whatever from
the applet and then IT writes to disk (or you hcould have
it opena socket to somewhere else and send the
string or bytes or whatnot to another server that's
listening that then writes to disk. Regardless, it's
a given that your going to have to jump through hoops.

With Respect,
Matt
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt:
A million thxs for your response.
Are you using appletviewer or IE or Netscape.
If you are using appletviewer, you can
achieve this without signing the applet.
One thing. Is c:\temp in your path?
Is the class that wants to write there
in your path. I can't remember exactly,
but one or the other or both needs to be.

I am using appletviewer and NS. First I want
it to work with the appeltviewer.
I added c:\temp and the dir I am running from to my path and classpath.
Ran the applet using appletviewer, but still end up with the same exceptions.
While I read the same things you mentioned but putting them into action is killing me.
Thanks for the tips.
I will gladly appreciate any other ideas.
Thanks.
- satya

[This message has been edited by Madhav Lakkapragada (edited March 07, 2001).]
[This message has been edited by Madhav Lakkapragada (edited March 07, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

knock...knock....knock....
Thanks.
- satya
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satya!
Here is a link that explains how to "Set up a Policy File to Grant the Required Permission".
http://java.sun.com/docs/books/tutorial/security1.2/tour1/step2.html
I edited your code slightly (see below) and tried it with appletviewer and it worked. I set my permission as follows:
FilePermission = java.io.FilePermission
TargetName = c:\\temp\\iotest.log
Actions = write


I have had limited success in granting permissions with Netscape. See this link for info: http://www.javaranch.com/ubb/Forum23/HTML/000234.html
Hope this helps.
Stephanie
 
priowan naratha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I do similar thing in writing to a file for unix system?
Thank you,
priowan
Originally posted by Stephanie Grasson:
[B]Hi Satya!
Here is a link that explains how to "Set up a Policy File to Grant the Required Permission".
http://java.sun.com/docs/books/tutorial/security1.2/tour1/step2.html
I edited your code slightly (see below) and tried it with appletviewer and it worked. I set my permission as follows:
FilePermission = java.io.FilePermission
TargetName = c:\\temp\\iotest.log
Actions = write


I have had limited success in granting permissions with Netscape. See this link for info: http://www.javaranch.com/ubb/Forum23/HTML/000234.html
Hope this helps.
Stephanie[/B]

 
Sean McGurk
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone know how I could modify this code so that it doesn't overwrite the prevoius entry in the file?

I think this code proves conclusively that Applets can read and write files on the server on which they are located.
i.e. That it is a syntactical rather than a security issue when writing files to the local disc.
Regards,
Sean

[This message has been edited by Sean McGurk (edited July 26, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would try this code to append:

the additional true keyword added to the FileWriter
constructor is for append.
Chk out the API for more details on this.
- satya

[This message has been edited by Madhav Lakkapragada (edited July 26, 2001).]
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK! A little different perspective. I HOPE everyone realizes that an applet can't literally "write" a file on the server, if for no other reason that a web server isn't a file server! The best it can do is pass data to the server and let the server do the writing. If you want to write a file on the client machine, of course, a whole different can of worms applies.
If you dig back through the Sun tech tips at java.sun.com, you should be able to find an article on creating temp files which uses OS-independent code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic