Show TOC Start of Content Area

Background documentation Developing Servlets  Locate the document in its SAP Library structure

Use

Servlets are Java applications that run on the server side and usually generate HTML-based dynamic content. Java EE application programmers typically use a combination of servlets, JSP components, and static HTML pages to create whole Web applications.

You can use the integrated SAP NetWeaver Developer Studio through the whole process of developing your servlets. It provides various features that simplify development, such as generating standard methods, import statements, and so on.

Procedure

...

       1.      Use the Servlet wizard in the SAP NetWeaver Developer Studio to create the stubs of the servlet component.

The Developer Studio creates a Java class implementing javax.servlet.Servlet or extending javax.servlet.http.HttpServlet, depending on the wizard settings you have chosen. This represents the main servlet component. The class also contains the methods you have specified in the wizard.

More information: Creating Servlets in the Developer Studio.

       2.      Optionally, customize the initialization logic of the servlet.

For example, you can read persistent configuration data (which you specified in the <init-param> tag of the deployment descriptor), initialize a resource that it uses, or another one-time activity for each servlet life-cycle.

More information: Initializing Servlets.

Note

All resources used by the servlet are injected to the servlet immediately before the servlet is initialized.

More information: Using Annotations in Web Applications.

       3.      Implement the essential logic of the servlet.

This can be done in two ways:

       By implementing the service method that was inherited from the generic javax.servlet.Servlet interface

       (If you are extending HttpServlet) By implementing one or more of the doGet, doPost, doPut, doTrace, doDelete, and doOptions methods. These correspond to the respective HTTP protocol methods (such as GET, POST and so on).

You manipulate the HTTP request object that the Web Container passes to the method, program some logic, and then send the results back to the client using the HTTP response object.

More information about implementing the basic servlet logic: Servicing Client Requests.

Optionally, you can provide the following features in the implementation of the latter method(s):

       Handle multiple servlet threads

More information: Threadsafe Servlets.

       Handle cookies

More information: Handling Cookies in Servlets.

       Manage HTTP sessions

More information: HTTP Sessions.

       Dispatch the received HTTP request to other resources such as servlets or JSP components

More information: Dispatching Requests to Web Application Resources.

       4.      Optionally, finalize the servlet operations.

For example, you can release all resources the servlet uses, or to save any persistent state before the servlet instance is destroyed.

More information: Destroying Servlet Instances.

       5.      Optionally, handle miscellaneous lifecycle events (for the servlet object or the HTTP session) by implementing event listeners.

More information: Developing Event Listeners.

 

End of Content Area