JasperReport打印时报错:java.security.AccessControlException: access denied

JasperReport在打印预览窗口中点击打印时出现如下错误:


打开控制台,

JasperReport打印时报错:java.security.AccessControlException: access denied_第1张图片

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.awt.windows)
	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.checkPackageAccess(Unknown Source)
	at sun.plugin2.applet.Applet2SecurityManager.checkPackageAccess(Unknown Source)
	at java.lang.Class.checkMemberAccess(Unknown Source)
	at java.lang.Class.getMethod(Unknown Source)
	at net.sf.jasperreports.engine.print.JRPrinterAWT.initPrinterJobFields(JRPrinterAWT.java:273)
	at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:140)
	at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:88)
	at net.sf.jasperreports.engine.JasperPrintManager.printPages(JasperPrintManager.java:348)
	at net.sf.jasperreports.engine.JasperPrintManager.printReport(JasperPrintManager.java:239)
	at net.sf.jasperreports.view.JRViewer$20.run(JRViewer.java:1090)
	at java.lang.Thread.run(Unknown Source)

这是因为applet在没有被允许的情况下去获取系统资源。

解决方法是

在JRE目录下lib/security中java.policy文件中添加授权,在grant下添加如下授权信息:

permission java.lang.RuntimePermission "accessClassInPackage.sun.awt.windows";

然后关闭浏览器重新启动,再打印,一切正常。

一般情况下,

java.security.AccessControlException: access denied 这个错误都是由于权限问题引起的,只要根据错误信息添加相应的授权信息即可解决。


你可能感兴趣的:(JasperReport打印时报错:java.security.AccessControlException: access denied)