What is Servlet ?
- Servlets are an important component of a J2EE application. Servlets along with JavaServer Pages (JSP) and EJB modules can be termed as server-side J2EE component types.
- Servlet is a Java Programming Language.
- Servlets are used to create web applications.
- Servlets are used to extend the applications hosted by web servers. Servlet runs in a J2EE application server
Common Gateway Interface (CGI) technology was used for dynamic content prior to introduction of Servlets.
Following diagram shows the process of Servlets in a Web Application.
The process can be summarized as follows:
- A client sends a request to a Web Server, through a Web Browser.
- The Web Server searches for the required Servlet and initiates it.
- The Servlet then processes the client request and sends the response back to the server, which is then forwarded to the client.
Advantages of a Servlet
- Servlets provide component based and platform-independent methods for building Web based applications.
- Each Request is run in a separate thread ,so servlet request processing is faster than CGI.
- Servlets overcomes the limitations of CGI program.
- Servlets run on Java Virtual Machine and in any platform and it is simple to write.
- Servlet are more powerful and the performance is better.
- Servlets are platform-independent.
- Servlet technology, in addition to improved performance, offers security, robustness, object orientation, and platform independence.
- As mentioned in the definition of servlets are fully integrated with the Java language and its standard APIs. Hence JDBC for Java database connectivity is also integrated in it.
- A servlet handles concurrent requests
- Handling HTTP requests and send text and data back to the client is made easy by servlet request and response objects.
Disadvantages of a Servlet
- Servlets often contain both business logic and presentation logic so it makes application difficult to understand.
- You would need JRE to be installed to run a servlet program.
Next Tutorial : Servlet API