I have a web application that uses a combination of JSP and Java Servlets. I use the JSP for the main form and all servlets for outputing the results.
I have used various techiniques for outputing the HTML show below, but they all seem a little rough and I was wondering what the best practice for this is?
Example1:
out.println("<html>");
out.println("<head>");
out.println("</head>");
...
Example 2:
out.println("<html> <head> </head> <body>") ...
Example 3:
String header = "<html> <head> </head> <body>";
output.println("<div> <p>" + result + "</p> </div>" );
Example 4:
Forward back to JSP for HTML and post result variable.
JSP is the view. Servlet is the controller. HTML is to be produced by the view. So, HTML belongs in JSP, not in Servlet.
See also: