• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic