Java Ajax 请求究竟是什么?它与 Servlet Request 不同吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2130239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:54:04  来源:igfitidea点击:

What exactly is Ajax request? Is it different from Servlet Request?

javaajax

提问by user241924

can anyone tell me. What exactly is Ajax request? Is it different from Servlet Request?

谁能告诉我。Ajax 请求究竟是什么?它与 Servlet Request 不同吗?

回答by zneak

An AJAX request is made (using Javascript) from the client, while a servlet request is made (using, I suppose, Java) from the server.

从客户端发出 AJAX 请求(使用 Javascript),而从服务器发出 servlet 请求(我想,使用 Java)。

I suggest you look it up on Wikipedia or some other place.

我建议你在维基百科或其他地方查一下。

回答by cletus

An Ajax call is an asynchronous request initiated by the browser that does not directly result in a page transition. A servlet request is a Java-specifc term (servlets are a Java specification) for servicing an HTTP request that could get a simple GET or POST (etc) or an Ajax request.

Ajax 调用是由浏览器发起的异步请求,不会直接导致页面转换。servlet 请求是一个 Java 特定术语(servlet 是一种 Java 规范),用于为 HTTP 请求提供服务,该请求可以获得简单的 GET 或 POST(等)或 Ajax 请求。

An Ajax ("Asynchronous Javascript and XML") request is sometimes called an XHR request ("XmlHttpRequest"), which is the name most browsers give the object used to send an Ajax request, because at least initially Ajax calls involved the sending and receiving of XML but now it's just as common to send/receive JSON, plain text or HTML.

Ajax(“异步 Javascript 和 XML”)请求有时称为 XHR 请求(“XmlHttpRequest”),这是大多数浏览器给用于发送 Ajax 请求的对象的名称,因为至少最初 Ajax 调用涉及发送和接收的 XML 但现在发送/接收 JSON、纯文本或 HTML 一样常见。

A good example of an Ajax request is the comment system on Stackoverflow. You can enter a comment in the textbox and click submit. It doesn't submit the whole page (like a traditional HTML form submission would, which translates into usually a POST but sometimes a GET HTTP request). Instead the browser will send probably a POST request via XHR to the server and be notified of the response (hence "asynchronous"). But the server typically can't distinguish between an Ajax request or a page transition because both simply come down to HTTP requests.

Ajax 请求的一个很好的例子是 Stackoverflow 上的评论系统。您可以在文本框中输入评论,然后单击提交。它不会提交整个页面(就像传统的 HTML 表单提交一样,通常会转换为 POST 但有时会转换为 GET HTTP 请求)。相反,浏览器可能会通过 XHR 向服务器发送一个 POST 请求,并收到响应通知(因此是“异步的”)。但是服务器通常无法区分 Ajax 请求或页面转换,因为两者都归结为 HTTP 请求。

回答by fastcodejava

Ajaxrequests are calls to the web server. It is up to you how you want to handle it. Servletis definitely one way.

Ajax请求是对 Web 服务器的调用。这取决于你想如何处理它。Servlet绝对是一种方式。

回答by Stephen C

The problem is that, like so many terms used in IT1there is no clear definition of either an "AJAX request" or a "Servlet request". The best I can come up with this is:

问题是,就像 IT 1 中使用的许多术语一样,“AJAX 请求”或“Servlet 请求”都没有明确的定义。我能想到的最好的是:

  • AJAX is short for "Asynchronous Javascript and XML", but these days the term is stretchedto include JSON rather than XML. The key idea is that logic embedded in the web page (in Javascript) makes asynchronous HTTP requests back to the "home" server to request more information, rather than triggering a refresh of the entire webpage.

  • An AJAX request is a request made by an AJAX application. Typically, it is an HTTP request made by (browser-resident) Javascript that uses XML to encode the request data and/or response data. The standard way of making an AJAX request in Javascript is to use an XmlHttpRequest object, but that is an implementation detail ... not fundamental to the definition of AJAX.

  • A Servlet request is a request made to a Servlet. In theory it need not even be an HTTP request, since Servlet technology is (in theory) designed to work over other protocols as well. To my mind, this is not a particularly useful term.

  • AJAX 是“Asynchronous Javascript and XML”的缩写,但如今该术语已扩展到包括 JSON 而不是 XML。关键思想是嵌入在网页中的逻辑(在 Javascript 中)使异步 HTTP 请求返回“主”服务器以请求更多信息,而不是触发整个网页的刷新。

  • AJAX 请求是由 AJAX 应用程序发出的请求。通常,它是由(驻留在浏览器的)Javascript 发出的 HTTP 请求,它使用 XML 对请求数据和/或响应数据进行编码。在 Javascript 中发出 AJAX 请求的标准方法是使用 XmlHttpRequest 对象,但这是一个实现细节......不是 AJAX 定义的基础。

  • Servlet请求是由请求到Servlet。理论上,它甚至不需要是 HTTP 请求,因为 Servlet 技术(理论上)也被设计为在其他协议上工作。在我看来,这不是一个特别有用的术语。

So ... an AJAX request can be a Servlet request or not, and a Servlet request can be an AJAX request or not.

所以... AJAX 请求可以是 Servlet 请求也可以是 Servlet 请求,Servlet 请求可以是 AJAX 请求也可以不是。

It is worth pointing out that there is a Java interface called ServletRequestthat forms part of the J2EE APIs. This interface is a type of the object that is used to pass details of a web request around in a J2EE-based web application container. So when you see someone use the term "Servlet request" they may actually be talking about a ServletRequestinstance.

值得指出的是,有一个称为 Java 接口的接口ServletRequest,它构成了 J2EE API 的一部分。此接口是一种对象,用于在基于 J2EE 的 Web 应用程序容器中传递 Web 请求的详细信息。因此,当您看到有人使用术语“Servlet 请求”时,他们实际上可能是在谈论一个ServletRequest实例。



1 - Actually, this is no different from any other natural language. Words and phrases gain meaning depending on how people use them, not based on any definition you may find in a dictionary. The dictionary "definition" tends to arrive years or decades after a word or phrase comes into common usage, and it gives a meaning based how the word is (or was) used, rather than being a specification of a meaning.

1 - 实际上,这与任何其他自然语言没有什么不同。单词和短语的含义取决于人们如何使用它们,而不是基于您在字典中可能找到的任何定义。字典的“定义”往往在一个词或短语被普遍使用后数年或数十年出现,它根据该词的使用方式(或曾经)给出含义,而不是对含义的说明。

回答by sap

Ajax, or Asynchronous JavaScript and XML, is an approach to Web application development that uses client-side scripting to exchange data with the Web server. As a result, Web pages are dynamically updated without a full page refresh interrupting the interaction flow.

Ajax 或异步 JavaScript 和 XML,是一种 Web 应用程序开发方法,它使用客户端脚本与 Web 服务器交换数据。因此,Web 页面会动态更新,而不会因为整个页面刷新而中断交互流程。

With Ajax, you can create richer, more dynamic Web application user interfaces.i.e. client side. On the other hand servlet requests are on server side to handle request sent from the UI.

使用 Ajax,您可以创建更丰富、更动态的 Web 应用程序用户界面。即客户端。另一方面,servlet 请求在服务器端处理从 UI 发送的请求。

When the visitor requests a page, the server will send the full HTML and CSS code at once. After the visitor fills in a form and submits it, the server processes the information( Servlet Request object provides client request information to a servlet. The servlet container creates a ServletRequest object and passes it as an argument to the servlet's service method) and rebuilds the page. It then sends the full page back to the client. And so on.

当访问者请求页面时,服务器将立即发送完整的 HTML 和 CSS 代码。访问者填写表单并提交后,服务器处理信息(Servlet Request 对象向 servlet 提供客户端请求信息。servlet 容器创建一个 ServletRequest 对象并将其作为参数传递给 servlet 的服务方法)并重建页。然后它将整个页面发送回客户端。等等。

When using AJAX, the page is loaded entirely only once, the first time it is requested. Besides the HTML and CSS code that make up the page, some JavaScript files are also downloaded: the AJAX engine. All requests for data to the sever will then be sent as JavaScript calls to this engine. The AJAX engine then requests information from the web server asynchronously ( servlet request object contains request parameters,which have got changed). Thus, only small page bits are requested and sent to the browser, as they are needed by the user. The engine then displays the information without reloading the entire page. This leads to a much more responsive interface, because only the necessary information is passed between the client and server, not the whole page.

使用 AJAX 时,页面仅在第一次请求时完全加载一次。除了构成页面的 HTML 和 CSS 代码外,还会下载一些 JavaScript 文件:AJAX 引擎。然后,所有对服务器的数据请求都将作为 JavaScript 调用发送到此引擎。然后,AJAX 引擎异步地从 Web 服务器请求信息(servlet 请求对象包含已更改的请求参数)。因此,只有小的页面位被请求并发送到浏览器,因为它们是用户需要的。然后引擎显示信息而不重新加载整个页面。这会导致响应速度更快的界面,因为在客户端和服务器之间只传递必要的信息,而不是整个页面。

For more info on ajax implementation we can refer http://www.ibm.com/developerworks/library/j-ajax1/

有关 ajax 实现的更多信息,我们可以参考http://www.ibm.com/developerworks/library/j-ajax1/

回答by guest

Ajax is not a programming language or a tool, but a concept. Ajax is a client-side script that communicates to and from a server/database without the need for a postback or a complete page refresh

Ajax 不是编程语言或工具,而是一个概念。Ajax 是一个客户端脚本,无需回发或完整的页面刷新即可与服务器/数据库进行通信