在java中调用servlet
如何调用 Servlet? doPost 和 doGet 之间有什么区别?欢迎任何解释链接,
谢谢
How do i invoke a Servlet? and What is the difference in between doPost and doGet? any links for explanation are welcome
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当向 servlet 容器发出与映射匹配的路径请求时,通常会通过 servlet 容器配置中的 servlet 映射来调用 servlet。
Sun上有许多资源可用于了解有关 servlet 的更多信息 Oracle Java 站点的 servlet 页面。 Wikipedia 上还有一篇介绍性文章。 编辑:在评论中,@BalusC 指出 StackOverflow 自己的 servlet 页面 标签 有很多有用的信息和链接——很好,Balus。doPost
当 HTTP 请求是POST
时被调用。doGet
当它是GET
时被调用。还有与其他 HTTP 动词相对应的其他方法。A servlet is typically invoked via a servlet mapping in your servlet container configuration, when a request is made to the servlet container for a path matching that mapping. There are a number of resources for learning more about servlets on the
SunOracle Java site's servlet page. There's also an introductory article on Wikipedia. Edit: In the comments, @BalusC points out that StackOverflow's own page for theservlet
tag has quite a lot of useful info and links — nice one, Balus.doPost
is called when the HTTP request is aPOST
.doGet
is called when it's aGET
. There are other methods corresponding to the other HTTP verbs.只需导航到 Web 应用程序中 web.xml 文件中指定的 URL 即可调用 servlet。因此,如果您的 servlet 名为 MyServlet,您的 web.xml 文件中可能会有类似这样的代码:
在此设置中,导航到 http: //myapplication.com/myservlet 将调用您的 servlet。
至于 doGet 和 doPost 的区别,唯一的区别是它们响应的 HTTP 方法,因为 servlet API 向程序员抽象了实际 HTTP GET 和 HTTP POST 方法之间的任何差异。这种抽象允许程序员使用单个接口从请求中获取参数,而不必担心如何传入参数。当将 HTTP GET 请求发送到 servlet 时(通常是直接导航到该请求),将调用 doGet。当 HTTP POST 请求发送到您的 servlet 时,将调用 doPost,这通常是通过来自另一个 html 页面的表单发布来完成的。
Invoking a servlet is done simply by navigating to the URL specified in your web.xml file in your web application. So if your servlet is called MyServlet you may have some code like this in your web.xml file:
In this setup, navigating to http://myapplication.com/myservlet would invoke your servlet.
As far as the difference in doGet and doPost, the only difference is the HTTP method they respond to, as the servlet API abstracts any differences between actual HTTP GET and HTTP POST methods away from the programmer. This abstraction allows the programmer to get parameters from the request using a single interface and not have to bother with how the parameters were passed in. doGet is called when a HTTP GET request is sent to your servlet, typically by navigating to it directly. doPost is called when an HTTP POST request is sent to your servlet, which is commonly done with a form post from another html page.
关于 POST 和 GET:学习一些 HTTP 基础知识
以及一些Servlet 基础知识
About POST and GET: learn some HTTP basics
And some Servlet basics