使用 RESTful Web 服务进行 Ajax 的好处?
如果我错了,请纠正我,但似乎很多人都在使用 RESTful Web 服务向 Ajax 提供数据。然而,普通的 Servlet 或 PHP 页面可以轻松地向 Ajax 应用程序提供该信息。因此,我没有看到创建 Web 服务(即使是 RESTful 服务)为 Ajax 调用提供数据的好处。
所以,我的问题是:使用 RESTful Web 服务(而不是使用简单的 Servlet 或 PHP 页面)来为 Ajax 应用程序提供响应有什么好处?
Correct me if I'm wrong, but it seems that many people are using RESTful web services to provide data to Ajax. However, a normal Servlet or PHP page can easily provide that information to Ajax applications. So, I don't see the benefit of creating web service, even a RESTful one, to provide data to Ajax calls.
So, my question is: what is the benefit of using a RESTful web service, rather than using a simple Servlet or PHP page to provide response to a Ajax application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RESTful Web 服务 使用 HTTP 协议和 HTTP 方法进行调用。 RESTful Web 服务没有任何像“大”(SOAP) Web 服务那样的特殊协议。
因此,Servlet 也可用于创建 RESTful Web 服务。事实上,如果您使用
doGet(-)
方法创建一个简单的 Servlet,您就创建了一个为GET
HTTP 方法调用提供服务的 RESTful Web 服务。简单的 PHP 页面也是如此。
如果您将 RESTful Web 服务称为即 JAX-RS 实现,那么它会为您带来灵活性和易于开发性(
@Produces
、@Consumes
、@FormParam
,多个@GET
方法等)RESTful Web Services are using the HTTP protocol and HTTP Methods for invocation. RESTful Web Services doesn't have any special protocol like "big" (SOAP) Web Services have.
Therefore, Servlets can be used to create RESTful Web Services as well. In the matter of fact, if you create a simple Servlet with
doGet(-)
method, you've just created a RESTful Web Service servingGET
HTTP Method invocations.The same is with your simple PHP page.
If you're referring to RESTful Web Services as an i.e. JAX-RS implementation, than it buys you a flexibility and ease of development (
@Produces
,@Consumes
,@FormParam
, multiple@GET
methods etc.)