O'Reilly logo

Sams Teach Yourself J2EE™ in 21 Days by Peter Roxburgh, Andy Longshaw, Debbie Law, Dan Haywood, Martin Bond

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

What Is a JSP?

A JSP is just another servlet, and like HTTP servlets, a JSP is a server-side Web component that can be used to generate dynamic Web pages.

The fundamental difference between servlets and JSPs is

  • Servlets generate HTML from Java code.

  • JSPs embed Java code in static HTML.

To illustrate this difference, Listings 13.1 and 13.2 are the same Web page coded as a servlet and as a JSP, respectively. Each Web page simply reads a parameter called name from the HTTP request and creates an HTML page displaying the value of the name parameter. Listing 13.1 shows the servlet, and Listing 13.2 shows the JSP.

Listing 13.1. Simple Dynamic Page As a Servlet
 1: import java.io.*; 2: import javax.servlet.*; 3: import javax.servlet.http.*; 4: 5: public ...

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