HttpServlet层次结构说明 [英] HttpServlet hierarchy explanation

查看:194
本文介绍了HttpServlet层次结构说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对java层次结构模型的一些事实有点关注。

I'm a little concern about some facts of java hierarchy model.

如java教程中所述:

As stated in java tutorials:


抽象类可能无法实现方法(但它们可以)并且如果
从抽象类扩展,则必须实现
超类的所有方法,否则新类必须也是抽象的

an abstract class may not implement methods ( but they can) and if you extend from an abstract class you must implement all methods of superclass otherwise the new class must be abstract as well

但是现在,我正在学习servlet类,发现我的servlet运行即使我没有实现在HttpServlet中声明的所有方法,发生了什么?我看到在源代码中它们是受保护的方法(dopost,doget等),甚至它表示已编译的代码)但即使它们受到保护我们如何扩展方法来创建新的servlet,是因为公共抽象HTTPservlet签名? 。

But right now, I'm learning servlets classes and found that my servlet runs even if I don´t implement all of the methods declared in HttpServlet, what is happening? I see that in the source they are protected methods (dopost, doget ,etc) and even it says compiled code) but even if they are protected how we can extend the methods to create new servlets, is it because the public abstract HTTPservlet signature? .

我也发现这很不寻常,这是什么意思?

I also found this very unusual, what's the meaning?

  private static final
    String METHOD_DELETE = "DELETE";
    private static final
String METHOD_HEAD = "HEAD";
private static final
String METHOD_GET = "GET";

当您查看实现servlet,servletconfig的公共抽象类GenericServlet时,所有其他理论都可以。序列化。这个想法是在未来有一个类,不一定需要实现像httpservlet那样的所有接口方法。

All other pieces of theory are ok when you look at Public abstract class GenericServlet which implements servlet, servletconfig, serializable. wich the idea is to have a class in the future that don't necessarily need to implements all interface methods like httpservlet does.

比你非常多,我也很感激更清晰或更深入的java类建模资源。

Than you very much, I also would appreciate clearer or deeper resources of java class modeling.

当抽象类被子类化时,子类通常为其父类中的所有抽象方法提供实现。但是,如果没有,那么子类也必须声明为abstract。

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.

是的,我误解并误读了httservlet规则只适用于抽象方法,没有正文只有签名,但httpsevlet方法不是抽象的,他们有实现但是编译=)谢谢你非常清楚为什么现在我们不需要实现那些方法和httpservlet使用的接口。

yeah i misunderstood and misread the httservlet the rule only applies to abstract methods with no body just the signature but httpsevlet methods are not abstract they have implementation but is compiled =) thank you very much i see why now we don't need to implement those methods and the interfaces used by httpservlet.

推荐答案


抽象类可能无法实现方法(但它们可以)并且如果从>抽象类扩展,则必须实现超类的所有方法,否则新类必须>抽象

an abstract class may not implement methods ( but they can) and if you extend from an >abstract class you must implement all methods of superclass otherwise the new class must be >abstract as well

我认为你误读了。

抽象类确实实现了方法,你就是不在将抽象类扩展为具体类之前,可以使用这些方法。通常这样做是因为抽象类中的方法将在各种扩展类中重用。这样做的一些原因是删除重复,并隐藏样板代码。

An abstract class does implement methods, you just don't get to use those methods until you extend the abstract Class into a concrete Class. Usually this is done because the methods in the abstract Class will be reused in various extending Classes. Some reasons for this are removing duplication, and hiding boiler plate code.

在HttpServlet中,您将获得所描述方法的默认实现。当您想要扩展HttpServlet的行为以满足您的特定需求时,可以覆盖您选择的那些。

In the HttpServlet you get default implementations of the methods you described. You Override the ones you select when you want to extend the behavior of HttpServlet to suit your specific needs.

这篇关于HttpServlet层次结构说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆