I just want to ask an opinion, which are the best practice to use html between this two option:1) Use JSP by creating html page there2) Generate html using Java server side by using PrintWriter Which one are the best practice?And if I got some situation like only to generate small line of html, is it better to create JSP page or just generate it using Java PrintWriter?Or there are any better approach?Thanks!
Java PrintWriter vs JSP
java;jsp
I would use a JSP every time. Why?Low-level programming HTML is a slow and error-prone operation. I've done this in C++ on an Arduino board, and I'm glad it was a hobby project.There is no way I could charge commercial rates for the small amount of functionality I produced.A JSP is very close to the HTML it emits, and so is easy to maintain.There are good libraries (JSTL for one) that simplify formatting output, handling loops etc.Investigate the use of scriptlet tags. These are easy to write, and allow encapsulating chunks of the JSP into a separate file. Typically these are used for things like input fields with an associated label and error reporting field. You can call the same scriptlet from multiple JSPs. In my experience, scriptlet tags have all but replaced tags written in Java.Having said that, JSPs are just one of many web templating options.This Wikipedia article provides a good comparison of the many options.