Show TOC Start of Content Area

Background documentation Web Components  Locate the document in its SAP Library structure

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:

·        javax.servlet.GenericServlet – these are servlets that are independent of the underlying transport protocol. The developer must take care of implementing the protocol specifics in the servlets code.

·        javax.servlet.http.HttpServlet – this in an HTTP-specific implementation of the GenericServlet. This class is designed to provide convenient API to Web application developers who develop servlets that communicate over HTTP. The major difference between the two classes is that the HttpServlet provides HTTP-specific methods such as doGet, doPost and so on, instead of the general service() method of the GenericServlet.

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:

·        JSP file – that is the text-based file with “.jsp” extension that contains the source of the JSP.

·        JSP page – more general term that refers mostly to the functions of the corresponding JSP, or the JSP as a component of a particular Web application.

 

End of Content Area