httpservlet的public service()方法和protected service()方法有什么区别 [英] what is the difference between public service() method and protected service() method of httpservlet

查看:222
本文介绍了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




从公共服务方法接收标准HTTP请求,
将它们发送到doXXX此类中定义的方法。这个
方法是
Servlet.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)方法的HTTP特定版本。这个方法没有必要覆盖

Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method. There's no need to override this method.



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




将客户端请求调度到受保护的服务方法。没有
需要覆盖此方法。

Dispatches client requests to the protected service method. There's no need to override this method.

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

You can see more here

http://docs.oracle。 com / javaee / 6 / api / javax / servlet / http / HttpServlet.html

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

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