GenericServlet,HttpServlet和Servlet有什么区别?

时间:2022-02-22 20:07:58

I was searching for exact difference between javax.servlet.http.HttpServlet , javax.servlet.GenericServlet and javax.Servlet unable to find it out.

我正在寻找javax.servlet.http.HttpServlet,javax.servlet.GenericServlet和javax.Servlet之间的确切区别,无法找到它。

"Exact Difference" means

“确切差异”是指

  1. Usage
  2. 用法
  3. Reason behind javax.servlet.GenericServlet existence
  4. javax.servlet.GenericServlet背后存在的原因

10 个解决方案

#1


24  

"Exact difference" meaning what? The API lists the exact differences.

“确切的差异”意味着什么? API列出了确切的差异。

Servlet is an interface defining what a servlet must implement.

Servlet是一个定义servlet必须实现的接口。

GenericServlet is just that, a generic, protocol-independent servlet.

GenericServlet就是一个通用的,独立于协议的servlet。

HttpServlet is a servlet tied specifically to the HTTP protocol.

HttpServlet是一个专门与HTTP协议绑定的servlet。

Are you asking when you'd use any of those?

你在问什么时候使用这些吗?

In general, you'd extend HttpServlet to implement an application's web layer.

通常,您将扩展HttpServlet以实现应用程序的Web层。

You might implement Servlet if you're writing your own container or handling everything yourself. You might extend GenericServlet to handle a different protocol, but you might not.

如果您正在编写自己的容器或自己处理所有内容,则可以实现Servlet。您可以扩展GenericServlet以处理不同的协议,但您可能不会。

#2


11  

javax.servlet

的javax.servlet

Servlet is a server-side web technology. As the name implies, it serves a client request and receives a response from the server. You have to implement javax.Servlet (Interface) to handle a servlet work.

Servlet是一种服务器端Web技术。顾名思义,它服务于客户端请求并从服务器接收响应。您必须实现javax.Servlet(接口)来处理servlet工作。

javax.servlet.GenericServlet

javax.servlet.GenericServlet的

Signature:

签名:

public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
  1. GenericServlet defines a generic, protocol-independent servlet.
  2. GenericServlet定义了一个通用的,与协议无关的servlet。
  3. GenericServlet gives a blueprint and makes writing servlet easier.
  4. GenericServlet提供了一个蓝图,使编写servlet变得更容易。
  5. GenericServlet provides simple versions of the life-cycle methods init and destroy and of the methods in the ServletConfig interface.
  6. GenericServlet提供了生命周期方法init和destroy的简单版本以及ServletConfig接口中的方法。
  7. GenericServlet implements the log method, declared in the ServletContext interface.
  8. GenericServlet实现了在ServletContext接口中声明的日志方法。
  9. To write a generic servlet, it is sufficient to override the abstract service() method.
  10. 要编写通用servlet,覆盖抽象service()方法就足够了。

javax.servlet.http.HttpServlet

javax.servlet.http.HttpServlet

Signature:

签名:

public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
  1. HttpServlet defines a HTTP protocol specific servlet.
  2. HttpServlet定义了一个特定于HTTP协议的servlet。
  3. HttpServlet gives a blueprint for Http servlet and makes writing them easier.
  4. HttpServlet为Http servlet提供了蓝图,使编写更容易。
  5. HttpServlet extends the GenericServlet and hence inherits the properties GenericServlet.
  6. HttpServlet扩展了GenericServlet,因此继承了GenericServlet属性。

#3


10  

javax.servlet.Servlet is interface, it defines methods for all the implementations - that's what interfaces usually do.

javax.servlet.Servlet是接口,它定义了所有实现的方法 - 这就是接口通常所做的事情。

javax.servlet.GenericServlet is protocol independent. It is abstract, so it is not to be directly instantiated. It is usable class to extend if you some day have to write servlet for protocol other than HTTP.

javax.servlet.GenericServlet与协议无关。它是抽象的,因此不能直接实例化。如果你有一天必须为HTTP以外的协议编写servlet,那么它是可用的扩展类。

javax.servlet.http.HttpServlet is abstract class to be extended if you want to communicate over HTTP protocol. Most likely you only have to care about this one.

如果要通过HTTP协议进行通信,javax.servlet.http.HttpServlet是要扩展的抽象类。很可能你只需要关心这个。

More exact information you can find behind the links.

您可以在链接后面找到更准确的信息。

#4


7  

-> One common feature is, both these Classes are Abstract Classes.

- >一个常见的特性是,这两个类都是抽象类。

-> GenericServlet is a super class of HttpServlet class.

- > GenericServlet是HttpServlet类的超类。

-> The main difference is that, HttpServlet is a protocol dependent whereas GenericServlet is protocol independent. So GenericServlet can handle all types of protocols, but HttpServlet handle only HTTP specific protocols.

- >主要区别在于,HttpServlet是依赖于协议的,而GenericServlet是独立于协议的。因此GenericServlet可以处理所有类型的协议,但HttpServlet只处理HTTP特定协议。

-> GenericServlet belongs to javax.servlet package. HttpServlet belongs to javax.servlet.http package

- > GenericServlet属于javax.servlet包。 HttpServlet属于javax.servlet.http包

-> GenericServlet is an abstract class which extends Object and implements Servlet, ServletConfig and java.io.Serializable interfaces. HttpServlet is an abstract class which extends GenericServlet and implements java.io.Serializable interface.

- > GenericServlet是一个抽象类,它扩展了Object并实现了Servlet,ServletConfig和java.io.Serializable接口。 HttpServlet是一个抽象类,它扩展了GenericServlet并实现了java.io.Serializable接口。

-> GenericServlet supports only service() method does not contain doGet() and doPost() methods. HttpServlet support also doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).

- > GenericServlet仅支持service()方法,不包含doGet()和doPost()方法。 HttpServlet还支持doGet(),doPost(),doHead()方法(HTTP 1.0)以及doPut(),doOptions(),doDelete(),doTrace()方法(HTTP 1.1)。

#5


3  

Servlet:-

Servlet的: -

  1. The Servlets runs as a thread in a web-container instead of in a seperate OS process.
  2. Servlet作为Web容器中的线程运行,而不是在单独的OS进程中运行。
  3. Only one object is created first time when first request comes, other request share the same object.
  4. 第一个请求到来时,第一次只创建一个对象,其他请求共享同一个对象。
  5. Servlet is platform independent.
  6. Servlet与平台无关。
  7. Servlet is fast.
  8. Servlet很快。

GenericServlet:-

GenericServlet类: -

  1. General for all protocol.
  2. 适用于所有协议。
  3. Implements Servlet Interface.
  4. 实现Servlet接口。
  5. Use Service method.
  6. 使用服务方法。

HttpServlet:-

HttpServlet的: -

  1. Only for HTTP Protocol.
  2. 仅适用于HTTP协议。
  3. Inherit GenericServlet class.
  4. 继承GenericServlet类。
  5. Use doPost, doGet method instead of service method.
  6. 使用doPost,doGet方法代替服务方法。

#6


2  

HttpServlet is specific to the HTTP protocol and hence it supplies methods for the HTTP verbs: doGet, doPost, etc, and a version of the generic service method that takes HTTP-specific request and response objects. It is a special type of Servlet which is actually a pretty minimal interface.

HttpServlet特定于HTTP协议,因此它为HTTP谓词提供方法:doGet,doPost等,以及获取特定于HTTP的请求和响应对象的通用服务方法的版本。它是一种特殊类型的Servlet,实际上是一个非常小的界面。

GenericServlet is the basic, protocol-neutral implementation of the Servlet interface. Often you'll find similar basic implementations of interfaces in an API; in this case GenericServlet adds a bit of functionality to the Servlet API: getServletName, getServletInfo, and pass-through methods for the servlet init parameters. HttpServlet benefits from these additions by extending GenericServlet.

GenericServlet是Servlet接口的基本协议中立实现。通常,您会在API中找到类似的接口基本实现;在这种情况下,GenericServlet为Servlet API添加了一些功能:getServletName,getServletInfo和servlet init参数的传递方法。通过扩展GenericServlet,HttpServlet可以从这些新增功能中受益。

Generally everyone coding against this API is using HttpServlet for implementing HTTP web services, but one can also extend or use GenericServlet for implementing server/service functionality using a custom protocol, or another extant protocol, for example, FTP.

通常,针对此API编码的每个人都使用HttpServlet来实现HTTP Web服务,但是也可以使用自定义协议或其他现存协议(例如,FTP)来扩展或使用GenericServlet来实现服务器/服务功能。

#7


2  

Servlet is an interface which contains five abstract methods in order use servlet we have to provide an implementation for all these five methods, which is a headache. In order to avoid this complexity, we have GenericServlet and HttpServlet for next level.

Servlet是一个包含五个抽象方法的接口,为了使用servlet,我们必须为所有这五个方法提供一个实现,这很令人头疼。为了避免这种复杂性,我们将GenericServlet和HttpServlet用于下一级。

GenericServlet is protocol independent, it means it can accept any protocol request. GenericServlet can forward and include a request but we can not redirect the request. Session Management with cookies and HttpSession is not possible in GenericServlet. In GenericServlet it is not possible to define separate logic for get and post request.

GenericServlet与协议无关,它意味着它可以接受任何协议请求。 GenericServlet可以转发并包含请求,但我们无法重定向请求。 GenericServlet中无法使用cookie和HttpSession进行会话管理。在GenericServlet中,无法为get和post请求定义单独的逻辑。

HttpServlet is protocol dependent. it means, it accepts only HTTP protocol request. HttpServlet can forward and include and redirect a request. Session Management with cookies and HttpSession is possible in HttpServlet. In HttpServlet it is possible to define separate logic for get and post request.

HttpServlet依赖于协议。这意味着,它只接受HTTP协议请求。 HttpServlet可以转发并包含和重定向请求。在HttpServlet中可以使用cookie和HttpSession进行会话管理。在HttpServlet中,可以为get和post请求定义单独的逻辑。

#8


2  

  1. Servlet interface
    Its the super interface for GenericServlet and HttpServlet. It contains 5 abstract methods and all inherited by GenericServlet and HttpServlet.
    • Problem
      If you want to create servlet by implementing Servlet interface all the 5 abstract methods of the interface Servlet should be overridden eventhough Programmer is not interested
    • 问题如果你想通过实现Servlet接口来创建servlet,那么应该覆盖Servlet接口的所有5个抽象方法,尽管Programmer不感兴趣
    • Usage
      Only implement Servlet interface if you like to develop your own container.
    • 用法如果您想开发自己的容器,请仅实现Servlet接口。
  2. Servlet接口它是GenericServlet和HttpServlet的超级接口。它包含5个抽象方法,并且全部由GenericServlet和HttpServlet继承。问题如果你想通过实现Servlet接口创建servlet,那么应该重写接口Servlet的所有5个抽象方法,尽管程序员不感兴趣用法如果你想开发自己的容器,只实现Servlet接口。
  3. GenericServlet
    Its the immediate subclass of Servlet interface and super class of HttpServlet. In this class, one abstract method exist: service(). Other 4 abstract methods are implemented in this class.
    • Problem
      All methods are concrete except service() method, So you have to implement it as a callback method.
    • 问题所有方法都是具体的,除了service()方法,所以你必须将它实现为回调方法。
    • Usage
      It is protocol independent so Can be used with any protocol like FTP, SMTP, HTTP etc.
    • 用法它独立于协议,因此可以与任何协议一起使用,如FTP,SMTP,HTTP等。
  4. GenericServlet它是Servlet接口的直接子类和HttpServlet的超类。在这个类中,存在一个抽象方法:service()。在这个类中实现了其他4种抽象方法。问题所有方法都是具体的,除了service()方法,所以你必须将它实现为回调方法。用法它独立于协议,因此可以与任何协议一起使用,如FTP,SMTP,HTTP等。
  5. HttpServlet
    Its subclass of both GenericServlet and Servlet interface. Immediate super class of HttpServlet is GenericServlet. HttpServlet does not contain any abstract method. Eventhough the HttpServlet does not contain any abstract methods, it is declared as abstract class by the Designers to not to allow the anyone to create an object directly because a Servlet object is created by the Servlet Container.
    • Problem
      HttpServlet is protocol dependent and used specific to HTTP protocol only.
    • 问题HttpServlet是依赖于协议的,仅用于HTTP协议。
    • Usage
      service() method need not be overridden. It can be replaced by doGet() or doPost() methods with the same parameters. Its most used method to create servlet.


      hierarchy
      Reference: way2java.com
    • 用法service()方法不需要重写。它可以用具有相同参数的doGet()或doPost()方法替换。它最常用的方法是创建servlet。层次结构参考:way2java.com
  6. HttpServlet它的GenericServlet和Servlet接口的子类。立即超级HttpServlet是GenericServlet。 HttpServlet不包含任何抽象方法。虽然HttpServlet不包含任何抽象方法,但设计者将其声明为抽象类,不允许任何人直接创建对象,因为Servlet容器是由Servlet容器创建的。问题HttpServlet是依赖于协议的,仅用于HTTP协议。用法service()方法不需要重写。它可以用具有相同参数的doGet()或doPost()方法替换。它最常用的方法是创建servlet。层次结构参考:way2java.com

#9


1  

-->GenericServlet can process multiple clients request from a single form. Whereas, HttpServlet can process multiple clients requesting from multiple HTML forms.

- > GenericServlet可以从单个表单处理多个客户端请求。然而,HttpServlet可以处理从多个HTML表单请求的多个客户端。

--> GenericServlet is Stateless and HttpServlet is Stateful.

- > GenericServlet是无状态的,HttpServlet是有状态的。

#10


0  

All classes, interfaces, and methods present in the javax.servlet package are protocol independent (generic to all protocols).

javax.servlet包中存在的所有类,接口和方法都是独立于协议的(所有协议都是通用的)。

In contrast, all classes, interfaces, and methods present in the javax.servlet.http package are protocol dependent (specific to the HTTP protocol)

相反,javax.servlet.http包中存在的所有类,接口和方法都依赖于协议(特定于HTTP协议)

#1


24  

"Exact difference" meaning what? The API lists the exact differences.

“确切的差异”意味着什么? API列出了确切的差异。

Servlet is an interface defining what a servlet must implement.

Servlet是一个定义servlet必须实现的接口。

GenericServlet is just that, a generic, protocol-independent servlet.

GenericServlet就是一个通用的,独立于协议的servlet。

HttpServlet is a servlet tied specifically to the HTTP protocol.

HttpServlet是一个专门与HTTP协议绑定的servlet。

Are you asking when you'd use any of those?

你在问什么时候使用这些吗?

In general, you'd extend HttpServlet to implement an application's web layer.

通常,您将扩展HttpServlet以实现应用程序的Web层。

You might implement Servlet if you're writing your own container or handling everything yourself. You might extend GenericServlet to handle a different protocol, but you might not.

如果您正在编写自己的容器或自己处理所有内容,则可以实现Servlet。您可以扩展GenericServlet以处理不同的协议,但您可能不会。

#2


11  

javax.servlet

的javax.servlet

Servlet is a server-side web technology. As the name implies, it serves a client request and receives a response from the server. You have to implement javax.Servlet (Interface) to handle a servlet work.

Servlet是一种服务器端Web技术。顾名思义,它服务于客户端请求并从服务器接收响应。您必须实现javax.Servlet(接口)来处理servlet工作。

javax.servlet.GenericServlet

javax.servlet.GenericServlet的

Signature:

签名:

public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
  1. GenericServlet defines a generic, protocol-independent servlet.
  2. GenericServlet定义了一个通用的,与协议无关的servlet。
  3. GenericServlet gives a blueprint and makes writing servlet easier.
  4. GenericServlet提供了一个蓝图,使编写servlet变得更容易。
  5. GenericServlet provides simple versions of the life-cycle methods init and destroy and of the methods in the ServletConfig interface.
  6. GenericServlet提供了生命周期方法init和destroy的简单版本以及ServletConfig接口中的方法。
  7. GenericServlet implements the log method, declared in the ServletContext interface.
  8. GenericServlet实现了在ServletContext接口中声明的日志方法。
  9. To write a generic servlet, it is sufficient to override the abstract service() method.
  10. 要编写通用servlet,覆盖抽象service()方法就足够了。

javax.servlet.http.HttpServlet

javax.servlet.http.HttpServlet

Signature:

签名:

public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
  1. HttpServlet defines a HTTP protocol specific servlet.
  2. HttpServlet定义了一个特定于HTTP协议的servlet。
  3. HttpServlet gives a blueprint for Http servlet and makes writing them easier.
  4. HttpServlet为Http servlet提供了蓝图,使编写更容易。
  5. HttpServlet extends the GenericServlet and hence inherits the properties GenericServlet.
  6. HttpServlet扩展了GenericServlet,因此继承了GenericServlet属性。

#3


10  

javax.servlet.Servlet is interface, it defines methods for all the implementations - that's what interfaces usually do.

javax.servlet.Servlet是接口,它定义了所有实现的方法 - 这就是接口通常所做的事情。

javax.servlet.GenericServlet is protocol independent. It is abstract, so it is not to be directly instantiated. It is usable class to extend if you some day have to write servlet for protocol other than HTTP.

javax.servlet.GenericServlet与协议无关。它是抽象的,因此不能直接实例化。如果你有一天必须为HTTP以外的协议编写servlet,那么它是可用的扩展类。

javax.servlet.http.HttpServlet is abstract class to be extended if you want to communicate over HTTP protocol. Most likely you only have to care about this one.

如果要通过HTTP协议进行通信,javax.servlet.http.HttpServlet是要扩展的抽象类。很可能你只需要关心这个。

More exact information you can find behind the links.

您可以在链接后面找到更准确的信息。

#4


7  

-> One common feature is, both these Classes are Abstract Classes.

- >一个常见的特性是,这两个类都是抽象类。

-> GenericServlet is a super class of HttpServlet class.

- > GenericServlet是HttpServlet类的超类。

-> The main difference is that, HttpServlet is a protocol dependent whereas GenericServlet is protocol independent. So GenericServlet can handle all types of protocols, but HttpServlet handle only HTTP specific protocols.

- >主要区别在于,HttpServlet是依赖于协议的,而GenericServlet是独立于协议的。因此GenericServlet可以处理所有类型的协议,但HttpServlet只处理HTTP特定协议。

-> GenericServlet belongs to javax.servlet package. HttpServlet belongs to javax.servlet.http package

- > GenericServlet属于javax.servlet包。 HttpServlet属于javax.servlet.http包

-> GenericServlet is an abstract class which extends Object and implements Servlet, ServletConfig and java.io.Serializable interfaces. HttpServlet is an abstract class which extends GenericServlet and implements java.io.Serializable interface.

- > GenericServlet是一个抽象类,它扩展了Object并实现了Servlet,ServletConfig和java.io.Serializable接口。 HttpServlet是一个抽象类,它扩展了GenericServlet并实现了java.io.Serializable接口。

-> GenericServlet supports only service() method does not contain doGet() and doPost() methods. HttpServlet support also doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).

- > GenericServlet仅支持service()方法,不包含doGet()和doPost()方法。 HttpServlet还支持doGet(),doPost(),doHead()方法(HTTP 1.0)以及doPut(),doOptions(),doDelete(),doTrace()方法(HTTP 1.1)。

#5


3  

Servlet:-

Servlet的: -

  1. The Servlets runs as a thread in a web-container instead of in a seperate OS process.
  2. Servlet作为Web容器中的线程运行,而不是在单独的OS进程中运行。
  3. Only one object is created first time when first request comes, other request share the same object.
  4. 第一个请求到来时,第一次只创建一个对象,其他请求共享同一个对象。
  5. Servlet is platform independent.
  6. Servlet与平台无关。
  7. Servlet is fast.
  8. Servlet很快。

GenericServlet:-

GenericServlet类: -

  1. General for all protocol.
  2. 适用于所有协议。
  3. Implements Servlet Interface.
  4. 实现Servlet接口。
  5. Use Service method.
  6. 使用服务方法。

HttpServlet:-

HttpServlet的: -

  1. Only for HTTP Protocol.
  2. 仅适用于HTTP协议。
  3. Inherit GenericServlet class.
  4. 继承GenericServlet类。
  5. Use doPost, doGet method instead of service method.
  6. 使用doPost,doGet方法代替服务方法。

#6


2  

HttpServlet is specific to the HTTP protocol and hence it supplies methods for the HTTP verbs: doGet, doPost, etc, and a version of the generic service method that takes HTTP-specific request and response objects. It is a special type of Servlet which is actually a pretty minimal interface.

HttpServlet特定于HTTP协议,因此它为HTTP谓词提供方法:doGet,doPost等,以及获取特定于HTTP的请求和响应对象的通用服务方法的版本。它是一种特殊类型的Servlet,实际上是一个非常小的界面。

GenericServlet is the basic, protocol-neutral implementation of the Servlet interface. Often you'll find similar basic implementations of interfaces in an API; in this case GenericServlet adds a bit of functionality to the Servlet API: getServletName, getServletInfo, and pass-through methods for the servlet init parameters. HttpServlet benefits from these additions by extending GenericServlet.

GenericServlet是Servlet接口的基本协议中立实现。通常,您会在API中找到类似的接口基本实现;在这种情况下,GenericServlet为Servlet API添加了一些功能:getServletName,getServletInfo和servlet init参数的传递方法。通过扩展GenericServlet,HttpServlet可以从这些新增功能中受益。

Generally everyone coding against this API is using HttpServlet for implementing HTTP web services, but one can also extend or use GenericServlet for implementing server/service functionality using a custom protocol, or another extant protocol, for example, FTP.

通常,针对此API编码的每个人都使用HttpServlet来实现HTTP Web服务,但是也可以使用自定义协议或其他现存协议(例如,FTP)来扩展或使用GenericServlet来实现服务器/服务功能。

#7


2  

Servlet is an interface which contains five abstract methods in order use servlet we have to provide an implementation for all these five methods, which is a headache. In order to avoid this complexity, we have GenericServlet and HttpServlet for next level.

Servlet是一个包含五个抽象方法的接口,为了使用servlet,我们必须为所有这五个方法提供一个实现,这很令人头疼。为了避免这种复杂性,我们将GenericServlet和HttpServlet用于下一级。

GenericServlet is protocol independent, it means it can accept any protocol request. GenericServlet can forward and include a request but we can not redirect the request. Session Management with cookies and HttpSession is not possible in GenericServlet. In GenericServlet it is not possible to define separate logic for get and post request.

GenericServlet与协议无关,它意味着它可以接受任何协议请求。 GenericServlet可以转发并包含请求,但我们无法重定向请求。 GenericServlet中无法使用cookie和HttpSession进行会话管理。在GenericServlet中,无法为get和post请求定义单独的逻辑。

HttpServlet is protocol dependent. it means, it accepts only HTTP protocol request. HttpServlet can forward and include and redirect a request. Session Management with cookies and HttpSession is possible in HttpServlet. In HttpServlet it is possible to define separate logic for get and post request.

HttpServlet依赖于协议。这意味着,它只接受HTTP协议请求。 HttpServlet可以转发并包含和重定向请求。在HttpServlet中可以使用cookie和HttpSession进行会话管理。在HttpServlet中,可以为get和post请求定义单独的逻辑。

#8


2  

  1. Servlet interface
    Its the super interface for GenericServlet and HttpServlet. It contains 5 abstract methods and all inherited by GenericServlet and HttpServlet.
    • Problem
      If you want to create servlet by implementing Servlet interface all the 5 abstract methods of the interface Servlet should be overridden eventhough Programmer is not interested
    • 问题如果你想通过实现Servlet接口来创建servlet,那么应该覆盖Servlet接口的所有5个抽象方法,尽管Programmer不感兴趣
    • Usage
      Only implement Servlet interface if you like to develop your own container.
    • 用法如果您想开发自己的容器,请仅实现Servlet接口。
  2. Servlet接口它是GenericServlet和HttpServlet的超级接口。它包含5个抽象方法,并且全部由GenericServlet和HttpServlet继承。问题如果你想通过实现Servlet接口创建servlet,那么应该重写接口Servlet的所有5个抽象方法,尽管程序员不感兴趣用法如果你想开发自己的容器,只实现Servlet接口。
  3. GenericServlet
    Its the immediate subclass of Servlet interface and super class of HttpServlet. In this class, one abstract method exist: service(). Other 4 abstract methods are implemented in this class.
    • Problem
      All methods are concrete except service() method, So you have to implement it as a callback method.
    • 问题所有方法都是具体的,除了service()方法,所以你必须将它实现为回调方法。
    • Usage
      It is protocol independent so Can be used with any protocol like FTP, SMTP, HTTP etc.
    • 用法它独立于协议,因此可以与任何协议一起使用,如FTP,SMTP,HTTP等。
  4. GenericServlet它是Servlet接口的直接子类和HttpServlet的超类。在这个类中,存在一个抽象方法:service()。在这个类中实现了其他4种抽象方法。问题所有方法都是具体的,除了service()方法,所以你必须将它实现为回调方法。用法它独立于协议,因此可以与任何协议一起使用,如FTP,SMTP,HTTP等。
  5. HttpServlet
    Its subclass of both GenericServlet and Servlet interface. Immediate super class of HttpServlet is GenericServlet. HttpServlet does not contain any abstract method. Eventhough the HttpServlet does not contain any abstract methods, it is declared as abstract class by the Designers to not to allow the anyone to create an object directly because a Servlet object is created by the Servlet Container.
    • Problem
      HttpServlet is protocol dependent and used specific to HTTP protocol only.
    • 问题HttpServlet是依赖于协议的,仅用于HTTP协议。
    • Usage
      service() method need not be overridden. It can be replaced by doGet() or doPost() methods with the same parameters. Its most used method to create servlet.


      hierarchy
      Reference: way2java.com
    • 用法service()方法不需要重写。它可以用具有相同参数的doGet()或doPost()方法替换。它最常用的方法是创建servlet。层次结构参考:way2java.com
  6. HttpServlet它的GenericServlet和Servlet接口的子类。立即超级HttpServlet是GenericServlet。 HttpServlet不包含任何抽象方法。虽然HttpServlet不包含任何抽象方法,但设计者将其声明为抽象类,不允许任何人直接创建对象,因为Servlet容器是由Servlet容器创建的。问题HttpServlet是依赖于协议的,仅用于HTTP协议。用法service()方法不需要重写。它可以用具有相同参数的doGet()或doPost()方法替换。它最常用的方法是创建servlet。层次结构参考:way2java.com

#9


1  

-->GenericServlet can process multiple clients request from a single form. Whereas, HttpServlet can process multiple clients requesting from multiple HTML forms.

- > GenericServlet可以从单个表单处理多个客户端请求。然而,HttpServlet可以处理从多个HTML表单请求的多个客户端。

--> GenericServlet is Stateless and HttpServlet is Stateful.

- > GenericServlet是无状态的,HttpServlet是有状态的。

#10


0  

All classes, interfaces, and methods present in the javax.servlet package are protocol independent (generic to all protocols).

javax.servlet包中存在的所有类,接口和方法都是独立于协议的(所有协议都是通用的)。

In contrast, all classes, interfaces, and methods present in the javax.servlet.http package are protocol dependent (specific to the HTTP protocol)

相反,javax.servlet.http包中存在的所有类,接口和方法都依赖于协议(特定于HTTP协议)