我应该覆盖service()或doPost()吗? [英] Should I override service() or doPost()?

查看:217
本文介绍了我应该覆盖service()或doPost()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本关于servlet的书,在那本书中给出了关于servlet类的简要解释,以及 HttpServlet 类。

I was reading a book on servlets, in that book a brief explanation is given about the servlet class, as well as the HttpServlet class.

有一个例子用于填写表单 - 该表格中,servlet的 doPost()方法被类重写。但是对于登录表单的另一个示例,将覆盖 service()方法。

There is one example for filling in a form- for that form, the servlet's doPost() method is overridden by the class. But for another example of a login form, the service() method is overridden instead.

我想知道为什么这两种不同的方法 - 我认为通常我们将自定义代码放入 doPost()(或 doGet() )并让 service()保持不变。使用这两种方法中的任何一种方法有什么原因,或者我可以在任何情况下使用这两种方法吗?

I want to know why the 2 different approaches- I thought that usually we put our custom code into doPost() (or doGet()) and let service() remain as it is. Is there any reason behind using either one of the 2 approaches, or can I use both approaches in any situation?

推荐答案

不要覆盖 service()方法。首选方法是使用 doPost()进行发布,使用 doGet()进行获取。这是一篇关于每项工作的优秀文章。 http://www.jguru.com/faq/view.jsp?EID=47730

Do not override service() method. The preferred approach is using doPost() for post and doGet() for get. Here is an excellent post on what each does. http://www.jguru.com/faq/view.jsp?EID=47730


如果您必须回应未使用
HTTP协议的客户端发出的请求,则必须使用service()。

If you must respond to requests made by a client that is not using the HTTP protocol, you must use service().

这篇关于我应该覆盖service()或doPost()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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