**7.1. Working and architecture of servlets**

## *7.1.1. Basic idea and architecture*

Web based technologies are of two different types: Client Side Technologies and Server Side Technologies. The Client Side Technology has the code completely downloaded on the client machine and executed on the client itself, any changes that need to be incorporated or updated in the application will be on client system after re-downloading by the client. The processing of this application will take place on the client, completely.

In a Server Side Technology the complete business logic is maintained on the server and on the request of the client it will be executed on the server, delivering the response to the clients. The Java Servlets technology provides on such simple, vendor-independent mechanism to extend the functionality of a web server [20]. Servlets technology is similar to common gateway interface (CGI) scripts, Javascripts (on client side) and hypertext preprocessor (PHP). Additionally, scripting languages can be used in servlets to dynamically modify or generate hypertext markup language (HTML) pages. It also supports various HTTP methods, such as GET and POST, which is used to redirect requests and responses as shown in **Figure 14**.

## *7.1.2. Working and life cycle*

Whenever a client sends a request to the J2EE application server for a particular servlet, the J2EE Application server passes the request to the Web container. The Web container checks

**Figure 13.** Remote evaluation.

**Figure 14.** Architecture of servlets.

**7. Remote evaluation**

18 New Trends in Industrial Automation

calculated subtasks into one single result.

**7.1. Working and architecture of servlets**

*7.1.1. Basic idea and architecture*

*7.1.2. Working and life cycle*

**Figure 13.** Remote evaluation.

In computer science, remote evaluation is a term that belongs to the family of mobile code, within the field of code mobility. It is for any technology that involves the transmission of executable software code from a client hosts to a server hosts for execution to be happen at the server and the result is sent back to the client after execution for this resources of server sside

An example for remote evaluation is grid computing: An executable task may be sent to a specific computer in the grid. After the execution has terminated, the result is sent back to the client. The client in turn may have to reassemble the different results of multiple concurrently

Web based technologies are of two different types: Client Side Technologies and Server Side Technologies. The Client Side Technology has the code completely downloaded on the client machine and executed on the client itself, any changes that need to be incorporated or updated in the application will be on client system after re-downloading by the client. The

In a Server Side Technology the complete business logic is maintained on the server and on the request of the client it will be executed on the server, delivering the response to the clients. The Java Servlets technology provides on such simple, vendor-independent mechanism to extend the functionality of a web server [20]. Servlets technology is similar to common gateway interface (CGI) scripts, Javascripts (on client side) and hypertext preprocessor (PHP). Additionally, scripting languages can be used in servlets to dynamically modify or generate hypertext markup language (HTML) pages. It also supports various HTTP methods, such as GET and POST, which is used to redirect requests and responses as shown in **Figure 14**.

Whenever a client sends a request to the J2EE application server for a particular servlet, the J2EE Application server passes the request to the Web container. The Web container checks

are used [19]. A simple model of remote evaluation is illustrated in **Figure 13**.

processing of this application will take place on the client, completely.

whether an instance of the requested servlet exists. If the servlet instance exists then the Web container delegates the request to the servlet, which process the client request and sends back the response (Shown in **Figure 15**).

It is the job of Web container to get the request and response to the servlet. The container creates multiple threads to process multiple requests to a single servlet. So in case the servlet instance does not exist, the Web container locates and loads the servlet class. The Web container then creates an instance of the servlet and initializes it. The servlet instance starts processing the request after initialization. The Web container passes the response generated by the servlet to the client.

Servlets don't have a main() method that's why Web container manages the life cycle of a Servlet instance. The life cycle of the servlet includes three states: new, ready and end. The servlet is in new state if servlet instance is created. After invoking the init() method, Servlet comes in the ready state [21]. In the ready state, servlet performs all the tasks. When the web container invokes the destroy() method, it shifts to the end state. It is shown in **Figure 16**.

## *7.1.3. Life cycle of servlet*


Method Signature: public void init(ServletConfig config) throws ServletException

**d.** Service method is invoked: The web container calls the service method each time when request for the servlet is received [22]. If servlet is not initialized, it follows the above three steps then calls the service method. The servlet is initialized only once so if servlet is already initialized, it directly calls the service method.

Method Signature: public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException.

**e.** Destroy method is invoked: The web container calls the destroy method before removing the servlet instance from the service. It gives the servlet an opportunity to clean up any resources like memory, thread etc. **Figure 16** shows life cycle methods of servlets.

**8. Conclusion**

**Figure 16.** Life cycle of servlets.

**Acknowledgements**

In the past couple of years there has been a development of enthusiasm for versatile platform innovation and a few stages have been developed and innovated to allow more independencies in programming platform. In this chapter we have surveyed and researched the various computing environment provided for remote execution that has incurred the need of mobile codes, intelligent agents, autonomous objects, etc. raising issues with flexibility, efficiency and security in present system that can promises to resolve existing problems and add on more facilities like remote execution, auto-scheduling and many more. Some of them have just been utilized for look into purposes while others have been conveyed as business items. A few technologies that incorporated in evolution of mobile agents have been discussed on the basis

Evolution and Paradigm Shift in Distributed System Architecture

http://dx.doi.org/10.5772/intechopen.80644

21

I would like to impart my sincere thanks to my guide Late. Dr. Rajesh Purohit, who has inspirited and fostered my interest in multifarious streams and disciplines of remoting and mobileobjects. Further I would like to extend my regards to all academic friends and lecturers who

of the usefulness of have been displayed in this exploration.

**Figure 15.** Various stages in request and response mechanism of servlets. (a) Clients request handling carried out by web container. (b) Object formation. (c) Calling servlet thread. (d) Thread execution. (e) Submission of response. (f) Final response toclient.

Evolution and Paradigm Shift in Distributed System Architecture http://dx.doi.org/10.5772/intechopen.80644 21

**Figure 16.** Life cycle of servlets.
