Posted by: sharko23 | April 10, 2007

Jasper Report …. and applet, local printing ….

On jasper report 1.2.8 there is example for printing report locally using applet jasperreports-1.2.8-applet.jar, (demo/samples/webapp)
But applet just “can not access local resource“, such as Printer and other file system.

after i try asking to my uncle “google” and my auntie “wiki” i found how to access printer using applet. The applet Must digitally certified using the keytool.exe found at
jre/bin.

So i create the certified jasperreports-1.2.8-applet.jar and the jasperreports-1.2.8.jar using Keytool. the following step is :

The keytool utility enables developers to generate public and private key pairs suitable
for signing applets. The Java Plug-in supports applets signed with RSA digital signatures.
To generate an RSA key pair, type the following at a command prompt:

keytool -genkey -keyalg RSA -alias sharko

The keytool utility prompts you for your name, organization name and location. To export
your digital signature into a certificate file, use the command:

keytool -export -alias sharko -file sharko.cer

The Java Plug-in maintains a keystore for trusted certificates in its lib/security
folder (e.g., C:\Program Files\JavaSoft\JRE\1.4.2\lib\security) named
cacerts. This keystore contains certificates from certificate authorities such as Verisign
and Thawte. The plug-in uses these certificates to verify digital signatures through a certificate
chain. Adding a new certificate to this keystore allows the Java Plug-in to verify applets
signed with that new certificate. (If your certificate has been signed by a Certificate Authority
such as Verisign or Thawte, you need not add this certificate to the cacerts trusted keystore.)
Add sharko.cer to the cacerts keystore using the command :

keytool -import -alias sharko -keystore cacerts -file sharko.cer

where cacerts is the complete path to the cacerts keystore in the Java Plug-in’s lib/
security folder. When prompted for a password, enter changeit, which is the cacert keystore’s default password.

Next, sign the applet’s JAR file with your digital signature using the jarsigner
utility. The jarsigner utility updates the manifest file in the JAR with the appropriate
security information and signs each class in the JAR file. To sign the JAR, enter the following
at a command prompt:

jarsigner jasperreports-1.2.8-applet.jar sharko

To enable the Web browser to load the Java Plug-in instead of the Web browser’s own
Java Virtual Machine, use the htmlconverter utility to convert the applet element
into appropriate object and embed elements using the command

htmlconverter printer.html

and load the resulting Web page in a Web browser. When the Java Plug-in loads the applet,
the plug-in displays the Java Plug-in Security Warning dialog. This dialog
displays information about the signing certificate and enables the user to grant special permission
to the applet. The user can click Grant this Session to allow the applet AllPermission
for the current browsing session, Deny to deny special permission to the
applet, Grant Always to allow the applet AllPermission for this and future browsing
sessions, or More Info to display detailed information about the applet’s signature.

build up your project and deploy.

Regs,

dedi m

Note: Taken from the Advanced Java 2 Platform HOW TO PROGRAM


Responses

  1. Bagaimana caranya supaya tidak muncul dialog box, Ikan Mas, eh Mas Ikan

  2. thanks , the above described solution helped me.
    bu i had one problem when i click print button
    directly it throwed java.security.AccessControlException to fix that i
    additionaly did one thing ,i added the PrinterApplet.class and all other releated class files to the jasperreports-1.2.7-applet.jar using this command
    jar uf jasperreports-1.2.7-applet.jar *.class
    and then i signed the applet.

  3. […] https://sharko23.wordpress.com/2007/04/10/jasper-report-and-applet-local-printing/ […]


Leave a comment

Categories