为什么要将接口声明为抽象?(Why declare an interface as abstract?)
什么是将接口声明为抽象? 接口方法相同的东西 有一点吗?
例如。
public abstract interface Presenter { public abstract void go(final HasWidgets container); }
What's point of declaring an interface as abstract? Same thing for an interface method. Is there a point to it?
eg.
public abstract interface Presenter { public abstract void go(final HasWidgets container); }
原文:https://stackoverflow.com/questions/2134200
最满意答案
destroy()
是卸载特定Servlet实例时由Servlet容器调用的生命周期方法。 同样,当有客户请求Servlet时, 容器将调用service()
。我们可以从Servlet中的
destroy()
方法调用service()
方法吗?简短的回答: 是的 ,因为
service()
是一种像其他任何方法一样的方法。长答案:你可以,但这没有意义。
service()
需要一个请求和一个响应参数,这些参数通常在调用Servlet时由容器提供。 如果你自己打电话给service()
,你将如何提供这些参数? 做什么的? 你会在两者上使用null
吗? 两个空参数的service()
什么好处?我们可以在Servlet中的
service()
方法中调用destroy()
方法吗?是的 ,您可以再次从
service()
调用destroy()
,因为它也是其他方法。 虽然仍然很奇怪,但有时这可能是有意义的,因为destroy()
会执行你定义的任何逻辑(清理,删除属性等)。
重要提示:请记住,简单地调用
destroy()
将不会卸载 Servlet实例。 您不管理程序中Servlet的生命周期,Servlet容器就是这样。
destroy()
is a lifecycle method called by the Servlet container when unloading a specific instance of the Servlet. Similarly, the container will callservice()
when there's a client requesting the Servlet.Can we call
service()
method fromdestroy()
method in Servlet?Short answer: Yes, as
service()
is a method like any other.Long answer: You can, but it doesn't make sense.
service()
requires a request and a response parameters that are usually provided by the container when the Servlet is called. If you are callingservice()
by yourself, how are you gonna provide those parameters? What for? Are you gonna usenull
on both? What good isservice()
for two empty parameters?Can we call
destroy()
method fromservice()
method in Servlet?Yes, again, you can call
destroy()
from within theservice()
as it is also a method like any other. Although still strange, this could make sense sometimes, asdestroy()
will do whatever logic you have defined (cleanup, remove attributes, etc.).
IMPORTANT: Just bear in mind that simply calling
destroy()
won't unload the Servlet instance. You do not manage the lifecycle of Servlets in the program, the Servlet Container does.
相关问答
更多-
我们可以从Servlet中的destroy()方法调用service()方法吗?(Can we call service() method from destroy() method in Servlet?)[2024-01-17]
destroy()是卸载特定Servlet实例时由Servlet容器调用的生命周期方法。 同样,当有客户请求Servlet时, 容器将调用service() 。 我们可以从Servlet中的destroy()方法调用service()方法吗? 简短的回答: 是的 ,因为service()是一种像其他任何方法一样的方法。 长答案:你可以,但这没有意义。 service()需要一个请求和一个响应参数,这些参数通常在调用Servlet时由容器提供。 如果你自己打电话给service() ,你将如何提供这些参数? ... -
根据服务器错误的建议,404的原因是您的路线。 代替 get "bands/favorite/:id" => "bands#destroy" 尝试: delete "bands/favorite/:id" => "bands#destroy" As suggested by the server error, the cause of your 404 is your route. Instead of get "bands/favorite/:id" => "bands#destroy" Try: del ...
-
您的web.xml和
-
在servlet中调用方法(calling method in servlet)[2023-09-26]
从Servlet类创建一个对象并调用该方法: public class Output extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Predicts p = new Predicts(); p.predict(); } } Cre ... -
编辑 : 你正在调用array.push而不是array.pushObject - 后者是一个绑定感知的Ember.js方法,这意味着它会自动更新绑定。 把手模板助手{{#each filters}}是对控制器的filters数组的绑定,模板需要知道在更新基础数组时更新。 push不告诉绑定更新,但pushObject确实如此。 这是一个有效的例子(我所做的就是将push推送到pushObject): http ://jsbin.com/asemul/6/ 这是一个非常常见的错误 - 通常,我发现如果我的模 ...
-
从**service method ()**只有你的实际方法(获取,发布...等)决定调用。 HTTP servlet中的默认service()方法将请求路由到基于HTTP传输方法(POST和GET)的另一个方法。 例如,HTTP POST请求被路由到doPost()方法,HTTP GET请求被路由到doGet()方法。 此路由使servlet能够根据传输方法执行不同的请求数据处理。 因为路由发生在service()中,所以您不需要覆盖HTTP Servlet中的service()。 相反,根据预期的请求类 ...
-
正在调用Servlet的服务和init方法,但不是doGet(Servlet's service and init method are being called, but not doGet)[2022-05-17]
你为什么要重写服务方法。 没有必要这样做。 删除它或打电话 super.service(request,response); 原因 试着看看HttpServlet类的来源。 在那里你会看到,根据用于调用servlet的方法,即GET / POST,调用必要的方法doGet()或doPost()。 当容器实际收到请求时,它会启动一个新线程并通过调用service()方法为客户端提供服务。 因此,如果你覆盖它并且不调用超类的服务方法或定义你自己的策略,那么将调用GET,永远不会调用doGet()方法。 您的请 ... -
如果响应对象由servlet容器提供,它可以控制如何处理缓冲等事情。 例如,假设您创建了自己的ServletResponse - 如果超过一定长度,容器如何管理响应流的能力,而不是缓冲数据? If the response object is provided by the servlet container, it can control how things like buffering are handled. For example, suppose you created your own Ser ...
-
这当然完全取决于您的实施。 如果你没有覆盖它,那么它什么都没做,因为在HttpServlet中destroy的实现是空的。 结果应用程序继续正常运行。 关于破坏方法的目的可能存在一些混淆。 目的不是servlet容器提供了一些破坏servlet的方法 。 相反,它使您可以提供一些代码,这些代码将在容器调用destroy方法时执行。 在某些情况下,当容器决定删除servlet时,需要清理资源(例如关闭数据库连接)。 容器可以独立地删除servlet:例如,如果内存不足。 方法destroy将被称为删除的一部分 ...
-
这意味着它将清除存储在与过滤器相关的内存中的所有数据,例如要允许的URL列表,要阻止的URL列表,某些处理必须应用的URL列表等。有时它需要让用户安全上下文采取行动(即是否阻止或允许)所有这些事情将在过滤器销毁期间释放。 It means it will clean all the data stored n memory related to the filters, for example the list of urls to allow, the list of urls to block, the ...