How Does JSP Work

To begin, let's look at the world's simplest JSP page, our version of the infamous “Hello World” program (see Listing 1.1).

Listing 1.1. HelloWorld.jsp
<HTML>
 <HEAD><TITLE>Hello World!</TITLE></HEAD>
 <BODY>Hello World!</BODY>
</HTML>

Okay, I can hear the screams of protest already. “That isn't JSP—that's plain old HTML. What are you trying to pull? I want my money back!”

It might look like innocent HTML, and if you put it into a .html file on a Web server, it would be delivered as straight HTML. But look what happens to this innocent little snippet in Listing 1.2 if you put it into a .jsp file instead.

Listing 1.2. HelloWorld as Java
 package org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL 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.