aspose file tools*
The moose likes Servlets and the fly likes Building HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Building HTML" Watch "Building HTML" New topic
Author

Building HTML

Richard Hooper
Greenhorn

Joined: Jan 30, 2006
Posts: 3
I want to create an HTML table from an array, apply loads of formatting and so on to it, and then output it in a JSP. I was going to do it all from scratch, and then I thought I could start off using XML instead to save myself some work, and then I found there were a whole load of standard HTMLElement etc classes too. But I just don't get how to use them in practice, and it seems hard to find any step-by-step tutorials for newbies!

Can anyone give me a few hints?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I would bind the array to one of the scoped objects, forward to a JSP, and then build the HTML by iterating over the array with JSTL.


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

Joined: Jan 30, 2006
Posts: 3
The thing is, I've got an existing application where the same JSP is used to output all manner of different reports, and they've only just realised that they want some specific formatting on some of bits. I don't want to have to have multiple JSPs if I can help it, and I don't want to fill the JSP with logic to work out how to display everything in all cases - that's why I want to do all the heavy lifting at the servlet end. I just can't get my head around using the XML API, even though it seems to be just the thing!

I may end up doing it some other way in the end, of course!
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
Check out the FormattedDataSet at www.fdsapi.com (one of my open source projects). It can create dynamic text (html, xml, and more) from tabular data (ResultSets, arrays and more). You can point the same data at different formatting templates. The API comes with a few default templates (xml, html table and a few others), and you can easily create more.

Here is how the code would work:


It is simple and fast. There is a live demo at the sight that creates dynamic content. If you have any questions let me know.
[ January 30, 2006: Message edited by: steve souza ]

http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Richard Hooper
Greenhorn

Joined: Jan 30, 2006
Posts: 3
I'll have a fiddle, looks good! Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Building HTML