Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to give access to the jar file of Applet for Scanner Plug-in ?

843807Feb 15 2008
Hi,

I am using Applet as an interface for HP SCANNER using the following jar file namely apple.jar.

I converted the following SaneAppletExample.java as apple.jar.

I found the below error while accessing the jsp file through browser. The applet does not support with the following error in the console.

I gone through more web sites for giving access to the jar file.


Thanks to help in this regards.

Thanks and regards,
S.P.Kannan.

Error Message:_
java.security.AccessControlException: access denied (java.util.PropertyPermission user.home 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.checkPropertyAccess(Unknown Source)
	at java.lang.System.getProperty(Unknown Source)
	at uk.co.mmscomputing.device.sane.applet.SaneAppletExample.init(SaneAppletExample.java:65)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
SaneAppletExample.java._
package uk.co.mmscomputing.device.sane.applet; 

import java.awt.Button;
import java.awt.GridLayout;
import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import uk.co.mmscomputing.device.scanner.Scanner;
import uk.co.mmscomputing.device.scanner.ScannerDevice;
import uk.co.mmscomputing.device.scanner.ScannerListener;
import uk.co.mmscomputing.device.scanner.ScannerIOMetadata;
import uk.co.mmscomputing.device.scanner.ScannerIOException;
import javax.swing.JFrame;

public class SaneAppletExample extends Applet implements ActionListener, ScannerListener{

  String  filename;

  Scanner scanner;
  Button  acquireButton,selectButton,cancelButton;

  public SaneAppletExample(){}

  public SaneAppletExample(String title, String[] argv){    
    JFrame.setDefaultLookAndFeelDecorated(true);

    JFrame frame=new JFrame(title);
//    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent ev) {
        stop();System.exit(0);
      }
    });

    init();

    frame.getContentPane().add(this);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    start();
  }

  public void init(){
    setLayout(new GridLayout(1,3));
    selectButton = new Button("select");
    add(selectButton);
    selectButton.addActionListener(this);

    acquireButton = new Button("acquire");
    add(acquireButton);
    acquireButton.addActionListener(this);

    cancelButton = new Button("cancel next scan");
    add(cancelButton);
    cancelButton.addActionListener(this);

    filename=System.getProperty("user.home")+"/test.jpg"; <---- Line No.65

    scanner=Scanner.getDevice();
    scanner.addListener(this);
  }

  public void actionPerformed(ActionEvent evt){
    try{
      if(evt.getSource()==acquireButton){
        scanner.acquire();
      }else if(evt.getSource()==selectButton){
        scanner.select();
      }else if(evt.getSource()==cancelButton){
        scanner.setCancel(true);
      }
    }catch(ScannerIOException sioe){
      sioe.printStackTrace();
    }
  }

  public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata){

    if(type.equals(ScannerIOMetadata.ACQUIRED)){
      BufferedImage image=metadata.getImage();
      System.out.println("Have an image now!");
      try{
        File file = new File(filename);
        System.out.println("Image Path: "+file.getAbsolutePath());
        ImageIO.write(image, "jpg", file);
      }catch(Exception e){
        e.printStackTrace();
      }
    }else if(type.equals(ScannerIOMetadata.NEGOTIATE)){
      ScannerDevice device=metadata.getDevice();
/*
      try{
//        device.setShowUserInterface(false);
        device.setShowProgressBar(true);
        device.setRegionOfInterest(20,40,300,200);
        device.setResolution(100.0);
      }catch(Exception e){
        e.printStackTrace();
      }
*/
    }else if(type.equals(ScannerIOMetadata.STATECHANGE)){
      System.err.println(metadata.getStateStr());
    }else if(type.equals(ScannerIOMetadata.EXCEPTION)){
      metadata.getException().printStackTrace();
    }
  }

  public static void main(String[] argv){
    try{
      SaneAppletExample app = new SaneAppletExample("Sane Applet Example [2007-11-19]", argv);
    }catch(Exception e){
      e.printStackTrace();
    }
  }
}
JSP FILE:
<table>
  <tr>
    <td>
	<APPLET CODE ="uk.co.mmscomputing.device.sane.applet.SaneAppletExample" ARCHIVE="apple.jar">
</APPLET>
      
    </td>
  </tr>
</table>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2008
Added on Feb 15 2008
0 comments
334 views