
Servlets and JSP pages are the two major types of Web components defined by the J2EE specification. They have specific characteristics and an established lifecycle that is managed by the Web Container.
Servlets
A servlet is a Java class that implements javax.servlet.Servlet interface. Servlets do not implement this interface directly, rather they extend the following classes that implement it:
A servlet has access to the request and response objects. It can read and set various request parameters or generate responses as Java objects. Servlets can use cookies to store session or application-related information and send it with the response to the client. You can program all these functions using simple methods provided by Java Servlet 2.3 API.
Java Server Pages
JSP pages are referred to as HTML (or XML) pages that embed Java code, which performs business logic. With the Java code fragments, JSP pages add dynamically generated content by other resources of the Web application to a static Web page. The standard means of inserting Java code are directives, actions and expressions. However, the Java Server Pages 1.2 Specification defines a way of extending the standard means by using JSP tag libraries.
JSP pages need not be compiled to deploy them on the J2EE Engine. The Web Container does that job later, when the first request to a JSP page arrives or when the application starts (depending on how you have configured your Web Container Service. For more information, see Specifying Compilation Time of JSP Files in the Administration Manual).
When describing Java Server Pages, we differentiate between the following two terms: