A Servlet That Generates HTML
public class HelloWWW extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"
"Transitional//EN\">\n";
out.println(
docType +
"\n" +
"Hello WWW\n"+
"\n" +
"Hello WWW
\n" +
""
);
}
}
13
Servlets
www.corewebprogramming.com
Some Simple HTML Building
Utilities
public class
ServletUtilities
{
public static final String DOCTYPE =
"
"Transitional//EN\">";
public static String
headWithTitle
(String title) {
return(DOCTYPE + "\n" +
"\n" +
"" + title + "\n");
}
...
}
Don't go overboard
Complete HTML generation packages
usually not worth the bother (IMHO)
The JSP framework is a better solution
14
Servlets
www.corewebprogramming.com
7