JAVA SERVLET
(Redirected from Servlet)
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 PHP, 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 , 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.
A is an object that receives a request and generates a response based on that request. The basic servlet package defines Java objects to represent servlet requests and responses, as well as objects to reflect the servlet's configuration parameters and execution environment. The package defines HTTP-specific subclasses of the generic servlet elements, including session management objects that track multiple requests and responses between the Web server and a client. Servlets may be packaged in a WAR file as a Web application.
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
# After initialization, the servlet can service client-requests. Each request is serviced in its own separate thread. The container calls the
# Finally, the container calls the
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 'Servlet container' is a specialized web server that supports Servlet execution. It combines the basic functionality of a web server with certain Java/Servlet specific optimizations and extensions – such as an integrated Java runtime environment, and the ability to automatically translate specific URLs into Servlet requests. Individual Servlets are registered with a Servlet container, providing the container with information about what functionality they provide, and what URL or other resource locator they will use to identify themselves. The Servlet container is then able to initialize the Servlet as necessary and deliver requests to the Servlet as they arrive. Many containers have the ability to dynamically add and remove Servlets from the system, allowing new Servlets to quickly be deployed or removed without affecting other Servlets running from the same container. Servlet containers are also referred to as 'web containers' or 'web engines'.
Like the other Java APIs, different vendors provide their own implementation of the Servlet container standard. Below is a list of some of the free and commercial web containers. (Note that 'free' means that non-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).
★ 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.
★ Geronimo Application Server is a full J2EE implementation by Apache.
★ Jetty
★ Jaminid contains a higher abstraction than servlets.
★ Enhydra
★ jo!
★ Winstone supports specification v2.4, has a focus on minimal configuration and the ability to strip the container down to only what you need.
★ tjws spec 2.4, small footprint, modular design
★ Java System Application Server
★ Java System Web Server
★ Caucho's Resin Server
★ BEA WebLogic Server or Weblogic Express
★ Borland Enterprise Server
★ Oracle Application Server
★ IBM's WebSphere
★ Macromedia JRun
★ IronFlare Orion Application Server
★ WebObjects
★ JBoss
★ GlassFish
★ LiteWebServer
★ JavaServer Pages
★ Java Enterprise Edition
★ Sun's servlet tutorial
★ Sun's servlet product description
★ JSR 154 (Servlet 2.4 and 2.5)
★ JSR 53 (Servlet 2.3)
★ New features added to Servlet 2.5 at JavaWorld
★ Java Documentation of the Servlet 2.3 API
★ An online viewable version of the 2.4 Servlet Specification
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 PHP, 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 , 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.
A is an object that receives a request and generates a response based on that request. The basic servlet package defines Java objects to represent servlet requests and responses, as well as objects to reflect the servlet's configuration parameters and execution environment. The package defines HTTP-specific subclasses of the generic servlet elements, including session management objects that track multiple requests and responses between the Web server and a client. Servlets may be packaged in a WAR file as a Web application.
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.
History
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.
| Servlet API version | Released | Platform | Important Changes |
|---|---|---|---|
| Servlet 2.5 | September 2005 | JavaEE 5 , J2SE 5.0 | Requires J2SE 5.0, supports annotations |
| Servlet 2.4 | November 2003 | J2EE 1.4, J2SE 1.3 | web.xml uses XML Schema |
| Servlet 2.3 | August 2001 | J2EE 1.3, J2SE 1.2 | Addition of Filters |
| Servlet 2.2 | August 1999 | J2EE 1.2, J2SE 1.2 | Becomes part of J2EE, introduced independent web applications in .war files |
| Servlet 2.1 | November 1998 | Unspecified | First official specification, added RequestDispatcher, ServletContext |
| Servlet 2.0 | JDK 1.1 | Part of Java Servlet Development Kit 2.0 | |
| Servlet 1.0 | June 1997 |
Life Cycle of a Servlet
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 request being made and dispatches it to an appropriate method to handle the request. The developer of the servlet must provide an implementation for these methods. If a request for a method that is not implemented by the servlet is made, the method of the parent class is called, typically resulting in an error being returned to the requester. # 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.ServletConfig and ServletContext
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.
Servlet Containers
A 'Servlet container' is a specialized web server that supports Servlet execution. It combines the basic functionality of a web server with certain Java/Servlet specific optimizations and extensions – such as an integrated Java runtime environment, and the ability to automatically translate specific URLs into Servlet requests. Individual Servlets are registered with a Servlet container, providing the container with information about what functionality they provide, and what URL or other resource locator they will use to identify themselves. The Servlet container is then able to initialize the Servlet as necessary and deliver requests to the Servlet as they arrive. Many containers have the ability to dynamically add and remove Servlets from the system, allowing new Servlets to quickly be deployed or removed without affecting other Servlets running from the same container. Servlet containers are also referred to as 'web containers' or 'web engines'.
Like the other Java APIs, different vendors provide their own implementation of the Servlet container standard. Below is a list of some of the free and commercial web containers. (Note that 'free' means that non-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).
Non-commercial web containers
★ 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.
★ Geronimo Application Server is a full J2EE implementation by Apache.
★ Jetty
★ Jaminid contains a higher abstraction than servlets.
★ Enhydra
★ jo!
★ Winstone supports specification v2.4, has a focus on minimal configuration and the ability to strip the container down to only what you need.
★ tjws spec 2.4, small footprint, modular design
Commercial web containers
★ Java System Application Server
★ Java System Web Server
★ Caucho's Resin Server
★ BEA WebLogic Server or Weblogic Express
★ Borland Enterprise Server
★ Oracle Application Server
★ IBM's WebSphere
★ Macromedia JRun
★ IronFlare Orion Application Server
★ WebObjects
Commercial open source web containers
★ JBoss
★ GlassFish
★ LiteWebServer
See also
★ JavaServer Pages
★ Java Enterprise Edition
External links
★ Sun's servlet tutorial
★ Sun's servlet product description
★ JSR 154 (Servlet 2.4 and 2.5)
★ JSR 53 (Servlet 2.3)
★ New features added to Servlet 2.5 at JavaWorld
★ Java Documentation of the Servlet 2.3 API
★ An online viewable version of the 2.4 Servlet Specification
Headline text
This article provided by Wikipedia. To edit the contents of this article, click here for original source.
psst.. try this: add to faves

العربية
中国
Français
Deutsch
Ελληνική
हिन्दी
Italiano
日本語
Português
Русский
Español