jspprinting-web-page

Printing web page programmatically in JSP


I have a J2EE based web application.

In one of the pages there is a button labeled "Print".

My problem is something like this:

User enters tool names for e.g: ToolName1 ToolName2 ToolName3

Then clicks on "Print".

The intended action is that tool details of the 3 tools are retrieved from db and then printed one tool per page. (i.e On clicking this button some processing should take place in the background db retrieval before sending the details to the printer...)

How best this task of printing the web page could be done?


Solution

  • The print button should submit the form to the server where you prepare the output you want to print (the tool details etc.). This is rendered as per usual using your JSP page or whatever.

    To complete the job, put a call to window.print() on the results page and have it fired on the page load (or document ready event).

    Edit: Hmm. I should have looked at the date. Oh well, the advice stands.