开发者

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

开发者 https://www.devze.com 2022-12-18 11:35 出处:网络
can anyone tell me. W开发者_运维问答hat exactly is Ajax request? Is it different from Servlet Request?An Ajax call is an asynchronous request initiated by the browser that does not directly result in

can anyone tell me. W开发者_运维问答hat exactly is Ajax request? Is it different from Servlet Request?


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.

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.

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, 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.

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.

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.

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.

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


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


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

  • AJAX is short for "Asynchronous Javascript and XML", but these days the term is stretched to 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.

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

It is worth pointing out that there is a Java interface called ServletRequest that 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 ServletRequest instance.


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.


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

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


Ajax requests are calls to the web server. It is up to you how you want to handle it. Servlet is definitely one way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号