*
The moose likes HTML, CSS and JavaScript and the fly likes how to print data from servlet to hp-printer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to print data from servlet to hp-printer" Watch "how to print data from servlet to hp-printer" New topic
Author

how to print data from servlet to hp-printer

darshan karle
Greenhorn

Joined: May 09, 2008
Posts: 28
hello everyone,

I am trying to print data from servlet to hp printer.i am new to it.
i it possible for anybody to send sample code. pleaseeeeeeee.
or paste web site name where i can find the code

regards
darshan
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you trying to send the job to a printer connected to the server or to the client's machine?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
darshan karle
Greenhorn

Joined: May 09, 2008
Posts: 28
thanks for the reply.
my system is connected to LAN network.
i want to send data to the printer connected to client machine
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by darshan karle:
...
i want to send data to the printer connected to client machine


In that case, this is more of an HTML question than a servlet question.
I'll move this to our HTML/Javascript forum for you.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

A servlet cannot print for a client for 3 reasons:

1. A servlet is built on HTTP, and HTTP can only respond to requests. If the browser makes a request, the response will go to the browser, so the browser would have to then route the output to a printer (more on this shortly). A printer doesn't make HTTP requests, so until someone invents one that can

2. The whole infrastructure of web client and web server is designed to sandbox out automated printing because believe it or not, people have using print subsystems to do rude, evil and abusive things.

3. The servlet doesn't know what the client's printing options are (what, if any printers are available and what drivers and print options to use).

A web client can print directly if it contains an applet that prints, but do to sandbox rules, this requires that the applet be digitally signed and that the client machine is set up to accept it. This is usually more trouble than it's worth.

More commonly, the applet simply generates an HTTP response that the user then prints using their browser's File/Print menu or a JavaScript function that does the same thing in software. The response is usually HTML, plain text or a PDF.


Customer surveys are for companies who didn't pay proper attention to begin with.
darshan karle
Greenhorn

Joined: May 09, 2008
Posts: 28
thanks for the reply,

can you please send the sample code to send data from browser to HP printer.
or send me the link where i can find more information about this.
please i am new to this topic.

regards
darshan
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
All you have to work with is window.print()

Eric
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Usually File --> Print works too Just have a style sheet that is media="print".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to print data from servlet to hp-printer