File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Printing with servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Printing with servlets" Watch "Printing with servlets" New topic

Printing with servlets

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Can anybody tell me how to print from a Servlet ?
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9058
It depends on where you want to print to. If you want to print to the screen, use PrintWriter and out.print. If you want to print to an error log, use System.out.print. Or are you talking about printing to a printer?

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
And is the printer connected to the server or the client? Most HTML/Browser applications which have a "print" button, just use it to produce an alternatively formatted version of the same data which will print sensibly.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ranch Hand

Joined: Apr 18, 2001
Posts: 46
There is no such way to get something printed by the servlet. But there is a good way in javascript. You can have the tested code from This piece of code has a javascript function which can be called either from body onLoad or by any click event on the page. This is a good alternative to anything.
Try seraching <b>print</b> on

Vikas Aggarwal
Technology Associate

Vikas Aggarwal<BR>Technology Associate<BR>
I agree. Here's the link:
subject: Printing with servlets
jQuery in Action, 3rd edition