Servlets, Advantages, Classes and Interfaces defined by javax.servlet package

Servlet: Servlet is a program which is executed on the web server. It is used to increase the functions of a web server.

Advantages of servlets:

1) Since a servlet works on the server side the performance is greatly increased.

2) Since servlets are solely written in Java, they are platform independent.

3) It communicates with applets, databases, and other softwares with the help of sockets and RMI (Remote method invocation).

4) Servlets are secure and they can be restricted to perform specific tasks.

To wrap servelts, javax.servlet package is used.

Classes defined by javax.servlet package:

  • ServletInputStream class: It provides an input stream for reading requests from a client.
  • ServletOutputStream class: It provides an output stream for writing responses to a client.
  • GenericServlet class: It is used to implement Servlet and ServletConfig interface.
  • ServletException class: It is used to inform that a servlet error has occurred.
  • UnavailableException class: It is used to inform that a servlet is unavailable.

Interfaces defined by javax.servlet package:

  • Servlet interface: It is used to define methods which controls the life cycle of a servlet.
  • ServletRequest interface: It is used to read data from a client request.
  • ServletResponse interface: It is used to write data to a client response.
  • ServletConfig interface: It provides initialization parameters for a servlet.
  • ServletContext interface: By the help of this interface servlets can log events and access environment information.
  • SingleThreadModel interface: It is used to inform that servlet is thread safe.

Leave a Reply