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.