probleme communication Java_Javascript
Bonjour,
J'ai developpé une applet qui peut avoir acces au disque dur de l'utilisateur, et ensuite envoyer les fichiers par ftp. Jusque la tout marche pour le mieux, apres avoir quand meme bloquer un peu sur la signature ?
Maintenant, je souhaite pouvoir creer un interfacage entre l'applet java et le javascript afin de pouvoir commander l'applet.
Tous fonctionne correctement sauf dans les cas ou la fonction appelé par javascript gere le JFileChooser, ce qui leve une exception. Tandis que cele fonctionne correctement via un appel par java.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public void acces_js() {//fonction appele par javascript
JFileChooser chooser = new JFileChooser();//création dun nouveau filechosser
chooser.setApproveButtonText("OK"); //intitulé du bouton
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
String nom = chooser.getSelectedFile().getAbsolutePath();
JSObject win = JSObject.getWindow(this);
String tet ="document.getElementById('texttest' ).innerHTML =" + nom+";" ;
// String tet = "alert('coucoul');";
win.eval(tet);
}
this.repaint();
}
//gestion evenement java
public void actionPerformed(ActionEvent evt) {
JFileChooser chooser = new JFileChooser();//création dun nouveau filechosser
chooser.setApproveButtonText("OKi"); //intitulé du bouton
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
String nom = chooser.getSelectedFile().getAbsolutePath();
JSObject win = JSObject.getWindow(this);
String tet ="document.getElementById('texttest' ).innerHTML ='" + nom+"';" ;
texte.setText(nom);
win.eval(tet);
}
this.repaint();
} |
Voici l'exception qui est geré:
java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(SecureInvocation.java:141)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(SecureInvocation.java:122)
at sun.plugin.navig.motif.AThread.handleRequest(Native Method)
at sun.plugin.navig.motif.AThread.JNIHandleLoop(AThread.java:40)
at sun.plugin.navig.motif.AThread.run(AThread.java:32)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.plugin.javascript.JSInvoke.invoke(JSInvoke.java:19)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.plugin.javascript.JSClassLoader.invoke(JSClassLoader.java:70)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(SecureInvocation.java:566)
... 7 more
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
at java.lang.System.getProperty(System.java:652)
at javax.swing.filechooser.FileSystemView.getHomeDirectory(FileSystemView.java:380)
at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(MetalFileChooserUI.java:247)
at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:136)
at javax.swing.plaf.metal.MetalFileChooserUI.installUI(MetalFileChooserUI.java:124)
at javax.swing.JComponent.setUI(JComponent.java:673)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1762)
at javax.swing.JFileChooser.setup(JFileChooser.java:360)
at javax.swing.JFileChooser.<init>(JFileChooser.java:333)
at javax.swing.JFileChooser.<init>(JFileChooser.java:286)
at test.comjavascript.acces_js(comjavascript.java:58)
... 17 more
Je me demande donc si il est possible que je puisse effectuer cette action par un appel de javascript , ou si elle est bloquée pour des raisons de securité ou autres?
Merci d'avance.