This article or section may contain spam.
Wikipedia spam consists of external links mainly intended to promote a website. Wikipedia spam also consists of external links to websites which primarily exist to sell goods or services, use objectionable amounts of advertising, or require payment to view the relevant content. If you are familiar with the content of the external links, please help by removing promotional links in accordance with Wikipedia:External links. (You can help!)
The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic Web content technologies such as CGI and ASP. NET. Servlets can maintain state across many server transactions by using HTTP cookies, session variables or URL rewriting.
The Servlet API, contained in the Java package hierarchy javax.servlet, defines the expected interactions of a Web container and a servlet. A Web container is essentially the component of a Web server that interacts with the servlets. The Web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights.
However, servlets can be generated automatically by JavaServer Pages (JSP), or alternately by template engines such as WebMacro. Often servlets are used in conjunction with JSPs in a pattern called "Model 2", which is a flavor of the model-view-controller pattern.
The original servlet specification was created by Sun Microsystems (version 1.0 was finalized in June 1997). Starting with version 2.3, the servlet specification was developed under the Java Community Process. JSR 53 defined both the Servlet 2.3 and JavaServer Page 1.2 specifications. JSR 154 specifies the Servlet 2.4 and 2.5 specifications. As of May 10, 2006, the current version of the servlet specification is 2.5.
In his blog on java.net, Sun veteran and GlassFish lead Jim Driscoll details the history of servlet technology. [1]James Gosling first thought of servlets in the early days of Java, but the concept did not become a product until Sun shipped the Java Web Server product. This was before what is now the Java Platform, Enterprise Edition was made into a specification.
The Servlet life cycle consists of the following steps:
The Servlet class is loaded by the container during start-up.
The container calls the init() method. This method initializes the servlet and must be called before the servlet can service any requests. In the entire life of a servlet, the init method is called only once.
After initialization, the servlet can service client-requests. Each request is serviced in its own separate thread. The container calls the service() method of the servlet for every request. The service() method determines the kind of HTTP request (GET, POST etc) and accordingly calls the methods doGet(), doPost(), doTrace() etc. The developer of the servlet must provide implementation for these methods. If an implementation for doPost() has not been provided, it means that the servlet cannot handle POST requests. In such a situation if a POST request is made, the implementation of the parent class will be invoked. By default, this will throw a BAD HTTP Request exception. A developer must never overload the service() method.
Finally, the container calls the destroy() method which takes the servlet out of service. The destroy() method like init() is called only once in the life-cycle of a Servlet.
There is only one ServletContext in every application. This object can be used by all the servlets to obtain application level information or container details. Every servlet, on the other hand, gets its own ServletConfig object. This object provides initialization parameters for a servlet. A developer can obtain the reference to ServletContext using either the ServletConfig object or ServletRequest object.
A Web container is a computer program that runs Web applications. Web containers are also sometimes called Web engines. Like the other Java APIs, different vendors provide their own implementation. Below is a list of some of the free and commercial web containers. (Note that 'free' means that commercial use is free. Some of the commercial containers, e.g. Resin and Orion, are free to use in a server environment for non-profit organizations).
Java System Application Server[2] is developed by Sun.
Apache Tomcat (formerly Jakarta Tomcat) is an open source web container available free of charge under the Apache Software License. It is used in the official reference implementation and has a reputation for being stable.