What are the classes and interfaces for servlets?

Answers were Sorted based on User's Feedback



What are the classes and interfaces for servlets?..

Answer / lal ajith kumara

Most commonly used interfaces and classes

javax.servlet.Servlet interface and
javax.servlet.ServletConfig interface
by implementing them we get

javax.servlet.GenericServlet

by extending GenericServlet we get
javax.servlet.http.HttpServlet

most ppl used HttpServlet to create Servlets

Is This Answer Correct ?    14 Yes 4 No

What are the classes and interfaces for servlets?..

Answer / niranjanravi

The Classes and interfaces in javax.Servlet interface are
Interface----------------------------------Classes
Servlet.................................GenericServlet

ServletRequest.....................UnAvailableException
ServletResponse......................ServletException
SingleThreadModel
the classes and Interfaces in javax.servlet.httpservlet are
classes---------------------------Interfaces
HttpServlet.......................HttpServletRequest
HttpUtils........................HttpSession

Is This Answer Correct ?    16 Yes 8 No

What are the classes and interfaces for servlets?..

Answer / keerthi

The javax.servlet package

The javax.servlet package defines the contract between
container and the servlet class. It provides the flexibility
to container vendor to implement the API the way they want
so long as they follow the specification. To the developers,
it provides the library to develop the servlet based
applications.
the javax.servlet Interfaces

The javax.servlet package is composed of 14 interfaces.
Servlet interface

The Servlet Interface is the central abstraction of the Java
Servlet API. It defines the life cycle methods of a servlet.
All the servlet implementations must implement it either
directly or indirectly by extending a class which implements
the Servlet interface. The two classes in the servlet API
that implement the Servlet interface are GenericServlet and
HttpServlet. For most purposes, developers will extend
HttpServlet to implement their Servlets while implementing
web applications employing the HTTP protocol.
ServletRequest interface

ServletRequest interface provides an abstraction of client
request. The object of ServletRequest is used to obtain the
client request information such as request parameters,
content type and length, locale of the client, request
protocol etc. Developers don’t need to implement this
interface. The web container provides the implementation
this interface. The web container creates an instance of the
implementation class and passes it as an argument when
calling the service() method.
ServletResponse interface

The ServletResponse interface assists a servlet in sending a
response to the client. Developers don’t need to implement
this interface. Servlet container creates the
ServletResponse object and passes it as an argument to the
servlet’s service() method.
ServletConfig interface

The servlet container uses a ServletConfig object to pass
initialization information to the servlet. ServletConfig
object is most commonly used to read the initialization
parameters. Servlet intialialization parameters are
specified in deployment descriptor (web.xml) file. Servlet
container passes the ServletConfig object as an argument
when calling servlet’s init() method.
ServletContext interface

ServletContext object is used to communicate with the
servlet container. There is only one ServletContext object
per web application (per JVM). This is initialized when the
web application is started and destroyed only when the web
application is being shutdown.
ServletContext object is most commonly used to obtain the
MIME type of a file, dispatching a request, writing to
server’s log file, share the data across application, obtain
URL references to resources etc.
SingleThreadModel Interface

SingleThreadModel is a marker interface. It is used to
ensure that servlet handle only one request at a time.
Servlets can implement SingleThreadModel interface to inform
the container that it should make sure that only one thread
is executing the servlet’s service() method at any given moment.
RequestDispatcher Interface

The RequestDispatcher interface is used to dispatch requests
to other resources such a servlet, HTML file or a JSP file.
Filter Interface

Filter interface declares life cycle methods of a filter.
The life cycle methods include, init() doFilter() and destroy().
FilterChain Interface

The FilterChain object provides the filter with a handle to
invoke the rest of the filter chain. Each filter gets access
to a FilterChain object when its doFilter() method is
invoked. Using this object, the filter can invoke the next
filter in the chain.
FilterConfig interface

The FilterConfig interface is similar to ServletConfig
interface. It is used to get the initialization parameters.
ServletContextAttributeListner

Implementation of this interface receives notification
whenever an attribute is added, removed or replaced in
ServletContext. To receive the notifications, the
implementation class must be configured in the deployment
descriptor (web.xml file).
ServletContextListner Interface

Implementation of this interface receives notification when
the context is created and destroyed.
ServletRequestAttributeListner Interface

Implementation of this interface receives notification
whenever an attribute is added, removed or replaced in
ServletRequest.
ServletRequestListner Interface

Implementation of this interface receives notification
whenever the request is coming in and out of scope. A
request is defined as coming into scope when it is about to
enter the first servlet or filter in each web application,
as going out of scope when it exits the last servlet or the
first filter in the chain.
The javax.servlet Classes
The javax.servlet package contains 9 classes.
GenericServlet class

The GenericServlet abstract class defines the generic
protocol independent servlet. It can be extended to develop
our own protocol-based servlet.
ServletContextEvent class

This is the event class for notifications about changes to
the servlet context of a web application.
ServletInputStream class

Provides an input stream for reading binary data from a
client request.
ServletOutputStream class

Provides an output stream for sending binary data to the client.
ServletRequestAttributeEvent class

This is the event class for notifications of changes to the
attributes of ServletRequest in an application.
ServletRequestEvent class

This event class indicates life cycle events of a
ServletRequest.
ServletRequestWrapper class

ServletRequestWrapper class provides a convenient
implementation of ServletRequest interface.
ServletResponseWrapper class

ServletResponseWrapper class provides a convenient
implementation of ServletResponse interface.
javax.servlet Exception classes
The javax.servlet package defines 2 exception classes.
ServletException class

Defines a general exception a servlet can throw when it
encounters difficulty.
UnavailableException class

Defines an exception that a servlet or filter throws to
indicate that it is permanently or temporarily unavailable.

Is This Answer Correct ?    3 Yes 1 No

What are the classes and interfaces for servlets?..

Answer / yogesh

Interfaces:Serialiazable- java.io.*;
ServletConfig -javax.servlet.*;
Servlet- javax.servlet.*;
classes: GenericServlet- javax.servlet.*;(abstract class)
HttpServlet-javax.servlet.http.*;(abstract class)

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Servlets Interview Questions

Explain the war file?

0 Answers  


What are the functions of Servlet container?

0 Answers  


Which exception is thrown if servlet is not initialized properly?

1 Answers  


What are the advantages of servlets over traditional cgi?

0 Answers  


Is dispatcher servlet a singleton?

0 Answers  






How to get the actual path of servlet in server?

0 Answers  


What is the type of method for sending request from http server?

0 Answers  


What is the ServletConfig() and what is its use?

4 Answers   Google,


can we override service method in my servlet class..?? if yes or no why ??

7 Answers   IBM,


How can we implement a jsp page?

0 Answers  


what are the disadvantages of cookies?

8 Answers  


What is meant by a web application

0 Answers  


Categories