File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Page Number on JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Page Number on JSP" Watch "Page Number on JSP" New topic

Page Number on JSP

Terence Chan

Joined: Nov 29, 2005
Posts: 4
Dear All,

I am trying to display page number on a jsp for a report task. Can any help?

I know I can let IE do the page number display but is there any other way of doing it?
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
The page number in IE, and Mozillla is an artifact of when the browser paginates the screen to fit onto paper when printing it.

If you have a report output and a JSP is rendering it as a long list on one page, you could have the logic that prints out the table in the JSP page to break up the table within the output, so that you can calculate the page number and display it.

for example,

Error: Keyboard not attached. Press F1 to continue.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

You have no way, on the server, of knowing how the browser is going to paginate your HTML output when it prints it. The user can direct the browser to change font size, to print in landscape instead of portrait mode, and so on. If you want to control the pagination then HTML is not the right tool. PDF would work better for that.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

There are ways of estimating it (MapQuest does a decent job at this) so you might be able to get close for practical purposes, but it'll never be precise. The best way, as previously mentioned, is to use PDF/PS exports.

[OCA 8 Book] [Blog]
Terence Chan

Joined: Nov 29, 2005
Posts: 4
Dear Travis, Paul, and Scott

First of all, thanks for all of your replies. Moreover, I am very interested in learning more on Travis sugguestion (Since I don't want to rewrite my whole program using pdf)! Appriecate if travis could give me detail (A complete example) on the solution.

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I guess using a third-party open source report frameworks is your best bet.
Like JasperReports, or JFreeReports
I agree. Here's the link:
subject: Page Number on JSP
It's not a secret anymore!