Hallo,
ich habe ein Applet, welches bei Button-Klick einen JFileChooser öffnet.
HTML:
Das Applet ist erfolgreich signiert (per SignTool.bat von L-ectron-X) sollte also auf das Dateisystem des Clients zugreifen können. Die Abfrage, ob man dem Zertifikat vertrauen möchte, kommt auch und ich klicke natürlich brav "Ja" an.
Beim Button-Klick bekomme ich nun die Fehlermeldung:
uncaught exception: java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
... was heißt, mein Applet ist nicht signiert ...
Gleiches Szenario, allerdings wird der JFileChooser sofort in der start()-Procedure aufgerufen:
gleiche Art der Signierung, ebenfalls erfolgreich, funktioniert ohne Probleme, bei Aufruf der Seite wird das Zertifikat abgefragt und nach dem Bestätigen wird der JFilechooser angezeigt ... allerdings bekomme ich dann ja nicht meinen Rückgabewert ins Textfeld.
Kann mir bitte jemand erklären woran das liegt. Ich bin völlig ratlos und weiß nicht, wo ich ansetzen kann, um das Problem zu lösen.
Danke für eure Hilfe,
chrissy
ich habe ein Applet, welches bei Button-Klick einen JFileChooser öffnet.
Java:
import java.applet.Applet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.AccessControlException;
import javax.swing.JFileChooser;
public class browser extends Applet
{
JFileChooser file;
public browser()
{
}
public static void main(String[] args)
{
browser browser = new browser();
browser.init();
browser.start();
}
public void start()
{
file = new JFileChooser();
}
public String showDialog()
{
String dir = new String();
file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = file.showDialog(null, "OK");
if (returnVal == JFileChooser.APPROVE_OPTION)
{
dir = file.getSelectedFile().getAbsolutePath();
if (dir.contains(":\\") )
{
String driveOld = dir.substring(0, dir.indexOf(":") + 1);
String driveNew = convertToUNCPath(driveOld);
if (driveNew != null) dir = dir.replace(driveOld, driveNew);
}
}
return dir;
}
private String convertToUNCPath(String path)
{
String s = null;
String unc = null;
String result ="";
StringBuffer command = new StringBuffer("C:\\Windows\\System32\\net.exe use ");
command.append(path);
try
{
Process p = Runtime.getRuntime().exec( command.toString() );
BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream()) );
while((s = in.readLine()) != null)
{
if (s.startsWith("Remotename")) unc =s.substring(12).trim();
}
}
catch (IOException e)
{
result = e.getMessage();
showStatus( result );
System.out.println(result);
}
catch ( AccessControlException e)
{
result = command + " " + e.getMessage();
showStatus( result );
System.out.println(result);
}
return unc;
}
}
HTML:
HTML:
<html><head><title>Test</title>
<script type="text/javascript">
function openDialog()
{
alert('hello');
var applet = document.getElementById("Hallo")
document.getElementById('textHelp').value = applet.showDialog();
}
</script>
</head><body>
<!--[if !IE]> Firefox and others will use outer object -->
<object classid="java:browser.class"
type="application/x-java-applet"
archive="FileBrowse.jar"
name="FileBrowaw" id="Hallo"
height="0" width="0">
<param name="archive" value="FileBrowse.jar" />
</object>
<!--<![endif]-->
<form name="Eingabe" action="">
<input type="text" name="Text" id="textHelp">
<input type="button" value="Test" onclick="openDialog();">
</form>
</body></html>
Das Applet ist erfolgreich signiert (per SignTool.bat von L-ectron-X) sollte also auf das Dateisystem des Clients zugreifen können. Die Abfrage, ob man dem Zertifikat vertrauen möchte, kommt auch und ich klicke natürlich brav "Ja" an.
Beim Button-Klick bekomme ich nun die Fehlermeldung:
uncaught exception: java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
... was heißt, mein Applet ist nicht signiert ...
Gleiches Szenario, allerdings wird der JFileChooser sofort in der start()-Procedure aufgerufen:
Java:
import java.applet.Applet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.AccessControlException;
import javax.swing.JFileChooser;
public class browser extends Applet
{
JFileChooser file;
public browser()
{
}
public static void main(String[] args)
{
browser browser = new browser();
browser.init();
browser.start();
}
public void start()
{
String dir = new String();
file = new JFileChooser();
file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = file.showDialog(null, "OK");
if (returnVal == JFileChooser.APPROVE_OPTION)
{
dir = file.getSelectedFile().getAbsolutePath();
if (dir.contains(":\\") )
{
String driveOld = dir.substring(0, dir.indexOf(":") + 1);
String driveNew = convertToUNCPath(driveOld);
if (driveNew != null) dir = dir.replace(driveOld, driveNew);
}
}
}
private String convertToUNCPath(String path)
{
String s = null;
String unc = null;
String result ="";
StringBuffer command = new StringBuffer("C:\\Windows\\System32\\net.exe use ");
command.append(path);
try
{
Process p = Runtime.getRuntime().exec( command.toString() );
BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream()) );
while((s = in.readLine()) != null)
{
if (s.startsWith("Remotename")) unc =s.substring(12).trim();
}
}
catch (IOException e)
{
result = e.getMessage();
showStatus( result );
System.out.println(result);
}
catch ( AccessControlException e)
{
result = command + " " + e.getMessage();
showStatus( result );
System.out.println(result);
}
return unc;
}
}
gleiche Art der Signierung, ebenfalls erfolgreich, funktioniert ohne Probleme, bei Aufruf der Seite wird das Zertifikat abgefragt und nach dem Bestätigen wird der JFilechooser angezeigt ... allerdings bekomme ich dann ja nicht meinen Rückgabewert ins Textfeld.
Kann mir bitte jemand erklären woran das liegt. Ich bin völlig ratlos und weiß nicht, wo ich ansetzen kann, um das Problem zu lösen.
Danke für eure Hilfe,
chrissy
Zuletzt bearbeitet von einem Moderator: