dcsimg
applet works with appletviewer but not with browser
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Sunday, January 4, 2009 06:36 AM

I am using filedialog to let the user choose the image to be displayed on the applet. The code works fine when I run the html file containing applet using appletviewer and the image is displayed properly. However if I use a browser, I keep getting the following exception: java.security.AccessControlException: access denied (java.io.FilePermission C:Documents and SettingsVJDesktopIMG00006.jpg read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Source) at java.io.File.isDirectory(Unknown Source) at   More>>

I am using filedialog to let the user choose the image to be displayed on the applet. The code works fine when I run the html file containing applet using appletviewer and the image is displayed properly. However if I use a browser, I keep getting the following exception:




java.security.AccessControlException: access denied (java.io.FilePermission C:Documents and SettingsVJDesktopIMG00006.jpg read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.isDirectory(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at LoadingAppletImages.getNewerImage(LoadingAppletImages.java:53)
at LoadingAppletImages.init(LoadingAppletImages.java:21)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)






I have changed my java policy file and added the following:





grant {
permission java.io.FilePermission " < >", "read";
};





Still the issue persists. Any suggestions?

Here is the code:

import java.awt.*;
import javax.swing.*;
import java.io.IOException;
import java.net.URL;
import java.applet.Applet;

public class LoadingAppletImages extends Applet {
public void init() {

JFrame frame = new JFrame();
FileDialog fd_review = new FileDialog(frame);
fd_review.setVisible(true);
fd_review.getFile();
String path = fd_review.getDirectory() +
System.getProperty("file.separator") + fd_review.getFile();

setLayout(new GridLayout(1,0));

Image image3 = getNewerImage(path);
add(new ImagePanel(image3));
}

private void loadImage(Image image) {
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
} catch(InterruptedException e) {
System.err.println("loading interrupted");
}
if(tracker.isErrorAny()) {
System.out.println("image loading status = " +
tracker.statusID(0, false));
}
}

private Image getNewerImage(String path) {
java.awt.image.BufferedImage image = null;
try {
// URL url = getClass().getResource(path);

image = javax.imageio.ImageIO.read(symantec.itools.net.RelativeURL.getURL("file:///"+path));
} catch(IOException e) {
System.err.println("read error: " + e.getMessage());
}
return image;
}

private class ImagePanel extends Panel {
Image image;
Dimension size;

ImagePanel(Image image) {
this.image = image;
size = new Dimension(image.getWidth(this),
image.getHeight(this));
}

public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}

public Dimension getPreferredSize() {
return size;
}
}
}


Thanks in advance.

   <<Less
About | Sitemap | Contact