更改服务方法中的 doGet() 和 doPost() 方法?

发布于 2024-12-22 09:12:55 字数 67 浏览 0 评论 0 原文

谁能告诉我服务方法中的doGet()doPost()方法如何变化?

Can anyone tell me how doGet() and doPost() method change in service method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

老街孤人 2024-12-29 09:12:55

如果客户端浏览器发送 GET 请求,它将由 doGet() 方法。
如果客户端浏览器发送 POST 请求,它将由 doPost() 方法。

这就是你想知道的吗? :O

更新:

服务(HttpServletRequest req,
HttpServletResponse resp)
方法,服务器使用HttpServletRequest.html#getMethod()。然后,它将该值与可用的 HTTP 方法类型进行比较,并调用相关的 doGetdoPost 或其他匹配方法。

请参阅 service(HttpServletRequest req, HttpServletResponse resp) 方法实现rel="nofollow">http://www.docjar.com/html/api/javax/servlet/http/HttpServlet.java.html

除了请求参数如何发送到服务器以及用法含义之外用于使用GETPOST 方法,据我所知没有其他变化。

if the client browser sends a GET request, it will handle by doGet() method.
if the client browser sends a POST request, it will handle by doPost() method.

Is that what you wanted to know? :O

UPDATE:

In side the service(HttpServletRequest req,
HttpServletResponse resp)
method, server get the request method using HttpServletRequest.html#getMethod(). Then it compare that value with available HTTP method types and call the relevant doGet, doPost or other matching method.

See service(HttpServletRequest req, HttpServletResponse resp) method implementation in http://www.docjar.com/html/api/javax/servlet/http/HttpServlet.java.html

Other than how the request parameters are sent to the server and the usage meant for using GET and POST methods, there is no other change AFAIK.

梦纸 2024-12-29 09:12:55

因为,在 HttpServlet 类中实现了服务方法,并且所有用户定义的 servlet 类都必须扩展 Httpservlet 类。它是一个库类。在该类中实现了 2 个服务方法。一个是 public void 服务方法,它基本上是 Servlet 接口方法。
另一个是带有 2 个参数的重载 protected void 服务方法 - HttpServletRequest 和 HttpServletResponse。
公共服务方法调用受保护服务方法和受保护服务方法,其中有一些逻辑。它检查客户端请求是哪种类型。如果是 GET 类型,则调用 doGet() 方法,如果是 POST 类型,则调用 doGet() 方法调用 doPost() 方法。
这两个方法也在 protected service() 方法中实现,但是我们在用户定义的 servlet 类中重写这些方法来执行我们的任务。

Because,In HttpServlet class service method is implemented and all user defined servlet class must extends Httpservlet class.It is a library class.Inside that class 2 service methods are implemented .one is public void service method ,which is basically Servlet interface method.
and another is overloaded protected void service method with 2 parameter-HttpServletRequest and HttpServletResponse.
public service method calls protected service method and proteced service method ,which has inside some logic.It checks which type of client request has come.if it is GET type then it will call doGet() method and if it is of type POST than it calls doPost() method.
these 2 methods are also implemented in protected service() method but we override these methods in user defined servlet class to perform our task.

南冥有猫 2024-12-29 09:12:55

您可以使用HttpServletRequest#getMethod()(发出此请求)验证请求方法类型。

You may verify the request method type using HttpServletRequest#getMethod() (which this request was made).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文