当前位置: 技术问答>java相关
关于applet的打印问题,用administrator权限仍然无法打印。(内详)
来源: 互联网 发布时间:2015-02-16
本文导语: 主题: applet 打印不被执行 运行环境: jdk appletviewer 权限: Windows 2000 Server Administrator 原程序: ---------------------------------------------------- import java.applet.Applet.*; import java.awt.*; import java.awt.event.*; import java.awt....
主题: applet 打印不被执行
运行环境: jdk appletviewer
权限: Windows 2000 Server Administrator
原程序:
----------------------------------------------------
import java.applet.Applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.util.*;
import javax.swing.*;
public class print extends Applet{
Button my_print=new Button("打印");
public void paint(Graphics g){
g.drawString("dfsdadfa",20,20);
}
public boolean action(Event evt,Object obj){
if(evt.target==my_print){
my_print.setLabel("yes");
PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printJob.defaultPage();
printJob.setPrintable(canvas, pageFormat);
try{
printJob.print();
}
catch(PrinterException exception){
my_print.setLabel("error");
}
}
return true;
}
public void init(){
add(my_print);
}
private PrintPanel canvas;
}
class PrintPanel extends JPanel
implements Printable
{ public void paintComponent(Graphics g)
{// super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
}
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException
{ if (page >= 1) return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.setPaint(Color.black);
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.drawString("!哈哈哈!",100,100);
return Printable.PAGE_EXISTS;
}
}
出现的错误提示:
---------------------------------------------------------------
java.security.AccessControlException: access denied (java.lang.RuntimePermission
queuePrintJob)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkPrintJobAccess(SecurityManager.java:13
51)
请问:
---------------------------------------------------------
是否需要数字签名才可打印,可我的是用administrator执行的,又是在appletviewer里。没有运行在浏览器上。
如果是需要数字签名,请问应该怎么样做?
如果不是,能够解释一下是什么原因?
谢谢!
运行环境: jdk appletviewer
权限: Windows 2000 Server Administrator
原程序:
----------------------------------------------------
import java.applet.Applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.util.*;
import javax.swing.*;
public class print extends Applet{
Button my_print=new Button("打印");
public void paint(Graphics g){
g.drawString("dfsdadfa",20,20);
}
public boolean action(Event evt,Object obj){
if(evt.target==my_print){
my_print.setLabel("yes");
PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printJob.defaultPage();
printJob.setPrintable(canvas, pageFormat);
try{
printJob.print();
}
catch(PrinterException exception){
my_print.setLabel("error");
}
}
return true;
}
public void init(){
add(my_print);
}
private PrintPanel canvas;
}
class PrintPanel extends JPanel
implements Printable
{ public void paintComponent(Graphics g)
{// super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
}
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException
{ if (page >= 1) return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.setPaint(Color.black);
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.drawString("!哈哈哈!",100,100);
return Printable.PAGE_EXISTS;
}
}
出现的错误提示:
---------------------------------------------------------------
java.security.AccessControlException: access denied (java.lang.RuntimePermission
queuePrintJob)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkPrintJobAccess(SecurityManager.java:13
51)
请问:
---------------------------------------------------------
是否需要数字签名才可打印,可我的是用administrator执行的,又是在appletviewer里。没有运行在浏览器上。
如果是需要数字签名,请问应该怎么样做?
如果不是,能够解释一下是什么原因?
谢谢!
|
编辑这个文件
x:program filesjavasoftjre1.3libsecurityjava.policy
全部删除,然后,内容如下:
grant {
permission java.security.AllPermission;
};
x:program filesjavasoftjre1.3libsecurityjava.policy
全部删除,然后,内容如下:
grant {
permission java.security.AllPermission;
};