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

Get Sams Teach Yourself J2EE™ in 21 Days 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.