JSP Processing

Before a JSP page is sent to a browser, the server must process all the JSP elements it contains. This processing is performed by a web container, which can be either a native part of a web server or a separate product attached to the web server. The web container turns the JSP page into a Java servlet, then executes the servlet.

Converting the JSP page into a servlet (known as the JSP page implementation class) and compiling the servlet take place in the translation phase. The web container initiates the translation phase for a JSP page automatically when the first request for the page is received. The translation phase takes a bit of time, of course, so users may notice a slight delay the first time they request a JSP page. The translation phase can also be initiated explicitly, to avoid hitting the first user with the delay. This is referred to as precompilation.

The web container is also responsible for invoking the JSP page implementation class to process each request and generate responses. This is called the request processing phase. The two phases are illustrated in Figure 1-2.

JSP page translation and processing phases
Figure 1-2. JSP page translation and processing phases

As long as the JSP page remains unchanged, the translation phase is skipped. When the page is modified, it goes through the translation phase again.

Let’s look at a simple example. In the tradition of programming books, we start with ...

Get JavaServer Pages Pocket Reference 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.