Home  >  Article  >  What classes does servlet inherit?

What classes does servlet inherit?

anonymity
anonymityOriginal
2019-05-06 13:33:049143browse

What classes does servlet inherit?

Servlet (Server Applet) is the abbreviation of Java Servlet, called a small service program or service connector, a server written in Java It is a terminal program that is independent of platform and protocol. Its main function is to browse and generate data interactively and generate dynamic Web content.

In the narrow sense, Servlet refers to an interface implemented by the Java language. In the broad sense, Servlet refers to any class that implements this Servlet interface. Generally, people understand Servlet as the latter. Servlets run in Java-enabled application servers. In principle, Servlets can respond to any type of request, but in most cases Servlets are only used to extend Web servers based on the HTTP protocol.

Let’s take a look at the servlet interface and its abstract class:

public interface Servlet { 
   public void init(ServletConfig config) throws ServletException;
   public ServletConfig getServletConfig();
   public void service(ServletRequest req, ServletResponse res )throws ServletException, IOException;
    public String getServletInfo();
    public void destroy();
}
public abstract class GenericServlet implements Servlet, ServletConfig,java.io.Serializable {}
public abstract class HttpServlet extends GenericServlet {}

Servlet interface - a general Servlet interface that defines the most basic functions of a Servlet
|
|- -GenericServlet abstract class-implements the service interface and implements most of its methods, but the service method is not implemented and requires developers to implement it themselves.
|
|--HttpServlet abstract class-inherits GenericServlet, implements the service interface, rewrites the service method, and determines the request method in the service method, and performs different processing according to different request methods XXXX. Such a class without abstract methods is for others to inherit and use
|
|--XXServlet class. Therefore, during development, we only need to write an XXServlet class, directly inherit HttpServlet, and rewrite the doGet and doPost method
to handle GET requests and POST requests

What classes does servlet inherit?

In general, the interfaces and classes related to servlets are as follows:

Interface: Servlet, ServletConfig, ServletRequest, ServletResponse, HttpServletRequest, HttpServletResponse, ServletContext

##Class: HttpServlet (abstract class), GenericServlet (abstract class)

The above is the detailed content of What classes does servlet inherit?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does frame mean?Next article:What does frame mean?