本文介绍了httpservlet的public service()方法和protected service()方法有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Servlet接口由服务方法组成,Httpservlet也包含自己的特定服务方法。在servlet生命周期中,在init方法之后调用HttpServlet的公共服务方法。如果是这样,当调用Httpservlet类的受保护服务方法时?

Servlet interface consist of service method and also Httpservlet contains its own specific service method. During servlet life cycle public service method of HttpServlet is invoked after init method. If so when the protected service method of Httpservlet class is invoked?

我在这两种服务方法之间有点混淆。请澄清我

I am in a bit confused between these two service methods. Please clarify me

推荐答案

Servlet接口定义了所有servlet必须实现的方法,而HttpServlet是一个抽象类,需要扩展(继承)以创建适用于Web应用程序(网站或在线应用程序)的HttpServlet。

The Servlet interface defines the methods that must be implemented by all the servlets and the HttpServlet is an abstract class that needs to be extended(inherit) to create a HttpServlet suitable for a web application(website or online application).

Servlet容器始终调用Servlet中定义的服务方法接口。这个服务方法的HttpServlet实现只是用HttpServletRequest和HttpServletResponse调用服务mehtod。

The Servlet container always call the service method defined in the Servlet interface. The HttpServlet implementation of this service method just call the service mehtod with HttpServletRequest and HttpServletResponse.

你可以在

protected void service(HttpServletRequest req,
                       HttpServletResponse resp)
                throws ServletException,
                       java.io.IOException





public void service(ServletRequest req,
                    ServletResponse res)
             throws ServletException,
                    java.io.IOException



您可以在此处查看更多信息

You can see more here

这篇关于httpservlet的public service()方法和protected service()方法有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:10