Implementing Servlets Using JSP

As you've seen, servlets are well suited to function as form processors. You write an HTML form, submit it using GET or POST, and process the results in the servlet. Alas, all those lines like

aWriter.println("<HTML><HEAD><TITLE>Some title</TITLE></HEAD>");

can get tedious. Sun has mixed HTML and Java in the same file to combat this problem. The solution is called Java Server Pages, or JSP. Listing 41.5 shows a small JSP file.

Code Listing 41.5. demo.jsp—This JSP Compiles into a Servlet When First Accessed
<HTML>
<HEAD><TITLE>Demo JSP</TITLE></HEAD>
<BODY>
<%@ page contentType="text/html" %>
<% out.println("Hello, world! from a JavaServer Page"); %>
</BODY>
</HTML>
					

To install and run a JSP in Jakarta Tomcat, ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.