• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic