How JavaServer Pages work

JSPs are executed in a JSP engine (also called a JSP container) that is installed on a Web or application server. The JSP engine receives a request from a client and delivers it to the JSP. The JSP can create or use other objects to create a response. For example, it can forward the request to a servlet or an EJB component, which processes the request and returns a response to the JSP. The response is formatted according to the template in the JSP and returned to the client.

Translating into a servlet class

You can deploy JSPs to the server in either source or compiled form. If a JSP is in source form, the JSP engine typically translates the page into a class that implements the servlet interface and stores it in the server’s memory. Depending on the implementation of the JSP engine, translation can occur at any time between initial deployment and the receipt of the first request. As long as the JSP remains unchanged, subsequent requests reuse the servlet class, reducing the time required for those requests.

Deploying the JSP as a compiled servlet class eliminates the time required to compile the JSP when the first request is received. It also eliminates the need to have the Java compiler on the server.

Requests and responses

Some JSP engines can handle requests and responses that use several different protocols, but all JSP engines can handle HTTP requests and responses. The JspPage and HttpJspPage classes in the javax.servlet.jsp package define the interface for the compiled JSP, which has three methods:

For more information about the EAServer implementation of the JSP engine, see “Using JSPs in EAServer”.