O'Reilly logo

Platinum Edition Using XHTML™, XML, and Java™ 2 by Andrew H. Watt, Mike Morgan, Jim O'Donnell, Eric Ladd

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required