GeeCON Prague 2014*
The moose likes Servlets and the fly likes How to build an in-memory Dynamic HTML from a Servlet or any Java class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to build an in-memory Dynamic HTML from a Servlet or any Java class?" Watch "How to build an in-memory Dynamic HTML from a Servlet or any Java class?" New topic
Author

How to build an in-memory Dynamic HTML from a Servlet or any Java class?

Chintan B Shah
Ranch Hand

Joined: Sep 23, 2008
Posts: 83
Hi all,

I have this scenario and need some help on what's right way to do it.

I need to build an in-memory Dynamic XHTML and pass it on to itext API to convert that XHTML to PDF. Data to be inserted in that in-memory HTML tags will come from a web-service or maybe a thirparty API.

So, 2 things I need help with is

1. How to generate Dynamic XHTML without using out.println("") in Servlet?
2. What is best way to populate data from web-service into Dynamic XHTML tags?

I already have a working prototype wherein a Java class returns StringBuilder object which has XHTML (but its all hard coded "Hello World" kind of HTML) and that StringBuilder object is converted to ByteArrayInputStream and given to DocumentBuilder and finally to iText API to convert to PDF.

We want to design this in a fashion so that we can re-use same architecture down the road to generate any PDF.

Thanks for help in advance.

Regards,
Chintan.


SCJA 1.0
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

You might consider an approach using filters and a response wrapper if you want to leverage JSP. (Yeah, I'm a manager -- I can use words like leverage.)

Or you might consider a templating engine such as FreeMarker.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: How to build an in-memory Dynamic HTML from a Servlet or any Java class?