Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Applets
Expertise: Beginner
Mar 19, 1997

Accessing Client Disk with 1.1

Question:
I read (somewhere) that the Java spec. allows for applet access to the local disk in a restricted way. That is, the client should be able to specify a directory on the disk that Java can access. Is this true? Netscape's implementation does not support this. Is this a Java language issue or Netscape implementation issue? How else could I implement some sort of file upload in Java?

Answer:
What an applet can or cannot do at runtime is determined by the particular implementation of the Java Security Manager that comes with the browser rather than the version of the Java language itself. In general, the Security Manager in a browser prevents applets from reading, writing, renaming or removing any files, but the details of how the policy is enforced is up to the browser. For example, the security manager in Netscape prevents applets from reading, writing or accessing any files whatsoever.

However, the security managers in Sun's Hotjava and Appletviewer are more configurable. They allow applets to read files when they are explicitly named on user-defined access control lists. The access control list is null by default but can be defined in the ~/.hotjava/properties file by the user.

(The "~" symbol refers to the user's home directory on UNIX systems. On a PC, if the web browser is installed in the C:\ drive, then the properties file resides in C:\.hotjava\properties)

The acl.read property specifies which files or directories are readable by applets and the acl.write property specifies which files or directories can be written by applets. When acl.read is not defined, no applet can read any file and likewise, so long as acl.write hasn't been defined, applets cannot write to any files.

You can define individual files or directories to be readable or writeable by simply adding a line to the properties file as follows:


                acl.read=/home/docs/resume

                acl.write=/htdocs/visitorcounter



                        -or-



                acl.read=/home/published/papers

                acl.write=/home/incoming/images



To define multiple items on the access control list, separate the entries,with a ":"

                acl.read=/home/docs/resume:/home/published/papers

                acl.write=/home/incoming/images:/htdocs/visitorcounter

Allowing an applet to read/write a directory means that it can read/write all the files in that directory, including any files in any subdirectories that might be hanging off that directory.

Also note that allowing write access to files or directories opens up your system to potential mischief by applets that might rename files, consume large amounts of disk space, remove your files, etc. Be cautious in using this scheme and avoid it if at all possible. Instead have your applets keep any state they need back on the server where they reside.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date