The mainstay of the WebSphere Application Server, or any other Java application server (BEA Weblogic, Tomcat/Jakarta),...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
is the servlet. A servlet is a specialized Java class (program). It requires a Java application server and an HTTP server.
The Java Servlet API is a set of Java classes that implement an interface between a Web server (HTTP server) and a Web client (browser). The Java Servlet API is implemented by two Java packages:
The javax.servlet package contains classes that are protocol-independent and may be used with any protocol such as HTTP or FTP. The javax.servet.http package contains classes that are HTTP-specific.
A Web client uses a standard URL to access an HTTP server. The HTTP server parses the request and passes the request to the Java application server (WebSphere) that loads the servlet (if it is not loaded), initializes the servlet, creates a thread for the client and invokes the servlet.
The servlet API includes function such as doGet to handle the HTTP GET method and the doPost that handles the HTTP POST method. Those functions retrieve parameters passed to the server by the client. Parameters may be passed either as QUERY_STRING (part of the URL via the GET method), or STDIN file (via the POST method). They parse the variables out, initiate them and translate any URLENCODEd strings.
The application server can load a servlet on demand or when the server is started. The application server is a sophisticated operating system that resides on top of the base machine operating system (OS/400 in our case). When a servlet is loaded, the server will cause it to execute its INIT method that can retrieve data or perform other general housekeeping functions.
The application server allocates threads on behalf of clients and makes requests and processes threads available to the one copy of the servlet. Variables may be global and shared between all clients, or they may be thread-specific and unique to the client. Client-specific data must be properly declared and managed via Java serialization and proper attribute declaration.
The application server can implement persistence so that a conversation between the client and the Web server may occur. The application manages the concept of session that retains variables and other resources for a specific user via a special servlet API class called the HTTPSession class.
Servlets can use the JDBC to retrieve data from the database and then format and write HTML back to the browser. The application server implements three methods to invoke other servlets on behalf of the client, linking, chaining, and direct Java calls. The servlet can also invoke Java Server Pages (JSP) to simplify the integration of variable data with HTML.
One of the best in-depth discussions of the servlet, which includes examples, is the IBM Redbook: Servlet and JSP Programming with IBM WebSphere Studio and Visual Age for Java SG24-5755-00.See also the Java Servlet Specification Version 2.3.
About the author: Bob Cancilla is managing director of IGNITe/400, an electronic iSeries 400 Internet users group. He is also author of the book Getting Down to e-business with AS/400.