Way2Java

Servlets Tutorial Architecture Introduction

For easy understanding, the Servlets Tutorial Architecture is given in Question/Answer format.

1. What is Component?

A Component is a reusable software unit.

2. What is server-side component?

In client/server communication, a server-side component is that one which is automatically invoked against client request, executed and responses to client fulfilling the requirement.

3. What is Web component?

A Web component on the server-side is the one invoked by the client using Web (Internet) as medium (interface) of communication.

4. What is Servlet?

A Servlet is server-side Java Web component written as per Servlet API specifications.

5. What is Container and Servlet container?

Container is a general computer term which looks after the execution of a program. Following are the responsibilities of a container.

Callback methods are those which are called automatically by the system. For example, main(String args[]) method in Java is a callback method called by JVM at the start of the execution. Here, I can name JVM is a container. Similarly, a browser is a container for an applet. Browser calls the callback methods of the applet like init(), start() etc. at appropriate times and also looks over the life cycle of applet.

Servlet container is responsible to execute the servlet. The callback methods called by the servlet container are init(), service() and destroy() (also known as life cycle methods). In our subsequent programs, we load Tomcat server which gets us the servlet container.

6. What is Servlet Architecture?

The architecture, here, discusses the communication interface, protocol used, requirements of client and server, the programming with the languages and software involved.

  1. In Web communication, the client and server uses Web (Internet) as an interface (medium) of communication. That is, both client and server should connect to Web (though an Internet Service Provider) to communicate, else, impossible to communicate. When connected, the simple client system can be called as "Web client" and the server can be called as "Web server". Other way to say simply, any client and server connected to Web are known as "Web client" and "Web server".
  2. The standard protocol used in the Web, now-a-days, is HTTP (HyperText Transfer Protocol) protocol. For this reason, the cleint and server are also can be called as "HTTP client" and "HTTP server" .
  3. When connected, the client sends a request and server responses. In Web terminology, use only the words of request and response (do not use like client sends and server replies) only. It is known as request/response paradigm (style).
  4. To send a request, the software to be loaded on the Web cleint is "Browser" (the same browser you use to connect to Internet). Similarly, the software required on the Web server is "Web server software". To get the Web server software (or servlet container), most commonly used server is Tomcat (of Apache), Weblogic (of BEA, now acquired by Oracle) and WebSphere (of IBM) etc.
  5. Responsibilities of Web client
  • Now choose such a software on the client which can fulfill the above requirements. Obviously, it is browser. Browser represents the client system. When I say the client, it means I am talking about the browser on the client. Client sends request means, the browser on the client sends. Write a program which can take care of the above requirements in such a language understood by the browser. The easiet language programmer prefers is HTML. For GUI, HTML comes with <FORM> tag. So, the client program is written in HTML (alternatively, you can use an Java Applet also).
  • Responsibilities of Web server
  • On the Web server-side, I prefer to use popular Tomcat. Tomcat understands Servlets and JSP apart other frameworks like Struts. Servlets are written in Java as per Servlet API specifications (rules) stipulated by Sun Microsystems.

    Now with this knowledge, let us write a small program of Login validations where client sends (as request) user name and password, server validates and responses valid or invalid.

    Pass your comments and suggestions to improve this tutorial on "Servlets Tutorial Architecture Introduction".