• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Signed applet and printing

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to create an applet that will print to a local printer. From what I have read I need a signed applet. I have managed to get a signed applet to work to allow me to write a file to my pc, but when attemting to read a file via FileInputStream I get:
Error: java.security.AccessControlException: access denied (java.io.FilePermission c:\Ticket.txt read)
The code I'm using is:
FileInputStream fis = new FileInputStream("c:\\Ticket.txt");
printStatus( new DataInputStream(fis).readLine());
fis.close();
I added this to my java.policy file:
grant signedBy "mySigner" {
permission java.io.FilePermission "C:\Ticket.txt", "read";
};
I read somewhere that FileInputStream should not be used when reading from the client but don't know what else to use.
Right now, I'm simply trying to read a text file and send it to the printer. What I ultimately would like to do is send a stream of text directly to the printer without a file. I'm completely new to Java so I've been doing lots of reading online to see that some people have been able to do similar things but have yet to find any good material to point me in the right direction.
If anyone has any information that can point me in the right direction I would greatly appreciate it.
Thanks,
Keith
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, why does this have to be an applet? Why not make it a Java application, then you don't have the security constraints to worry about.
Next, you're mixing apples and oranges. Printing is a visualization of data with ink on paper - you have to have some visual UI component that's been realized, either on the screen or in an offscreen buffer, in order to print it. Unless you're talking about sending a Postscipt file to the printer.
If you just want to print something from an applet to test printing, I suggest you abandon the whole FileIO issue for now. Just draw something in your applet's Graphics, and provide a button on the applet that will print the contents of the Graphics.
And like I mentioned earlier, you might find it easier to work with a Java Application instead of an Applet while you're learning the Printing API.
 
Keith Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I'll give a little more detail about what I'm doing. We are in the process of creating a box office ticketing application that is web based. It is written using ASP/Javascript and running solely in IE 6. At each ticket window will be a pc running Win 2k which is connected to a ticket printer. When the ticket is sold, via the browser based application, I need to print a ticket to the locally connected printer.
To do what I need, to the best of my knowledge, I need an Applet. I imagine some sort of ActiveX control could be written but I tend to think the Applet would be the best solution, if I can get it to work. I will not be displaying the ticket to the screen anywhere. I would simply like to allow the user to click on a button that will call a javascript function that will then call an applet to send a stream of data to the windows printer. I am able to do this fine in VB but, not being able to execute a dll from the browser (unless there is a way) then I figured Java was my only solution.
Hopefully this will shed a little light on what I am trying to accomplish. I have seen discussions online where people seem to have done very similar things but with little to no detail and being inexperienced in Java, detail is what I need. At least a boost in the right direction. I'm struggling through signing an applet now and have most of that working now but will really need to understand how to send a stream of data to a printer. This will include formatting the document, etc.
Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic