Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

java - Copy/Paste not working in a signed Applet

I've a signed applet (which verifies correctly with jarsigner) that for some reason will not allow copy and paste from the system clipboard into a JTextField despite the documentation telling me that it is supposed to work for signed applets.

Furthermore, I've other applets which are signed with the same keyfile that do let me copy and paste text. I have searched high and low on the internet and can't seem to find any clues. What is making me pull my hair out is that there seems to be no way to debug this (no output in the console - no thrown exceptions).

Does any one have any ideas on how I can debug this to find out why Java doesn't like this particular applet?

Many thanks for any suggestions!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, it turns out with the release of the Java Plug-in 1.6.0_24 in February 2011, copy and paste from the system clipboard was deemed a security hole and disabled. You can copy and paste BETWEEN applets. But if you try to use something from your main clipboard, it can't be copied in.

So there are a couple of options for a workaround. You can roll back to an earlier version of the plug-in. That will work, but chances are all future releases will still keep copy and paste disabled, so you'd never be able to upgrade.

The other alternative is to provide a custom java security policy file which enables access to the system clipboard again.

First locate your local Java Security Policy file. The file is named java.policy and should be in the libsecurity folder of your Java installation. On Windows 7, it can be found at C:Program Files (x86)Javajre6libsecurity. Copy this file to your home folder (ex. C:UsersKyle). Rename the file to .java.policy (note the period at the beginning). Edit the file in a text editor. Locate this line of text:

// "standard" properies that can be read by anyone

Add the following line just below it like so:

// "standard" properies that can be read by anyone
permission java.awt.AWTPermission "accessClipboard";

Save the file. Close any open browsers and ensure that Java is not running before testing.

source: http://blogs.oracle.com/kyle/entry/copy_and_paste_in_java


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...