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.
- Renders services to execute a program (application).
- Responsible to call the callback methods whenever required for the smooth execution of the program.
- Responsible to maintain the life cycle of the program (application).
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.
- 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".
- 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" .
- 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).
- 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.
- Responsibilities of Web client
- Should be able to take request from the client by displaying some GUI environment (like user name and passowrd as in Login screen).
- To extract the data entered by the user and send it to the Web server as request.
- Should be able to receive what the server responses and display to the user.
- Should be able to receive the request send by the Web client.
- As per the request, load an appropriate servlet, execute it and send the output of execution as response to client.
- When response is delivered close the connection.
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".