Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

Skeleton Code

This magercise takes you through the steps necessary to allow an applet to write to a local file. Using policytool, you open up a selected part of the Java security model to permit this capability. The JRE's access controller will not permit access to other files.

See the A Quick Look at policytool course section for additional information.

Perform the following tasks:

  1. Compile the PLTester.java program. It contains a JTextField that contains a file to save to, a JTextArea that contains the text to save, and a JButton to save the text area to the file specified by the text field, when the button is selected.

  2. Save the PLTester.html loader and try the program without using policytool. Select Save to try to save the contents to any filename entered. This will generate a security violation.

  3. Start up policytool.

  4. Open the real policy file.

  5. Select Add Policy Entry and enter "file:." in the CodeBase field. This means you are updating the security policy for classes loaded from the current directory.

  6. Next select Add Permission to bring up the Add New Permissions screen.

  7. For a permission, select FilePermission in the first option.

  8. For a target, enter the filename you wish to make writable.

  9. For the actions option, either select write or enter write in the field to its right.

  10. Then select OK to close this window.

  11. On the Policy Entry window, select Done.

  12. On the opening screen, select File|Save to update the policy file.

  13. At this point, rerun the test applet and see if the file is writable. Try different values for the filename to ensure ONLY that file is writable and nothing else.

  14. After testing the applet, be sure to remove the entry from the policy file with policytool. Just select the appropriate code base from the policy file then select Remove Policy Entry to get rid of it and confirm the removal. Next select File|Save to save the updated policies.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and a demonstration of the expected behavior.

Copyright © 1998 MageLang Institute. All Rights Reserved.

[ This page was updated: 16-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.