Generate Static HTML Pages using Java -


i have unique problem solve. need dynamically create html based reports using standard template. contents of report created java program makes sense create new class uses jsp* make static html output file.

here gist:

myobject me = new myobject(); me.process();  myjsp jsp = new myjsp(me); file output = jsp.renderfrom("templatefile.jsp"); 

and output static, self contained html file can open in ie/firefox , see report.

what pattern/framework should follow allow me best accomplish this?

some notes: not webapp. creating html based reports, won't used webapp. rather not use string.format(".. giant template string .. ", args) clumsy. rather have template file this:

<html> <head><title>first jsp</title></head> <body>   <%     double num = math.random();     if (num > 0.95) {   %>       <h2>you'll have luck day!</h2><p>(<%= num %>)</p>   <%     } else {   %>       <h2>well, life goes on ... </h2><p>(<%= num %>)</p>   <%     }   %>   <a href="<%= request.getrequesturi() %>"><h3>try again</h3></a> </body> </html> 

where "dynamic" aspects of template can use myobject properties, etc.

lastly, plan use java 7 due issues having java 8. if there better way in java 8, let me know...

*after negative comments against jsp, perhaps jsp not right option. other library fine too, long works java.

use template engine this! recommend freemarker, velocity or stringtemplate. google it. of these engines cover needs.


Comments