OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification
11.1. Understand the interactions that are essential to asynchronous web pages
11.2. Understand the role of AJAX-style client side programming
AJAX Asynchronous JavaScript and XML
Exchanges data with the server, and updates parts of a web page without reloading the whole page.
XMLHttpRequest
var xmlhttp = new XMLHttpRequest();
Send request to a server
XMLHttpRequest
var xmlhttp = new XMLHttpRequest();
Send request to a server
- open(method, url, async) - -> the url can be txt xml, asp, php files in the server
- send(), send(string) -- > in post request
xmlhttp.open("GET", "hello.txt", true);
xmlhttp.send();
Get a response from a server
xmlhttp.responseText
xmlhttp.responseXML
onReadyStateChange Event
xmlhttp.onreadystatechange=function()
{...
xmlhttp.open("GET", "hello.txt", true);
xmlhttp.send();
Get a response from a server
xmlhttp.responseText
xmlhttp.responseXML
onReadyStateChange Event
xmlhttp.onreadystatechange=function()
{...
-xmlhttp.readyState, when is 4 is OK
-xmlhttp.status, when is 200 is OK
11.3. Implement asynchronous servlets using the facilities of Java EE6
asyncSupported can be used with @WebServlet or @WebFilter
Example:
@WebServlet(url="/foo" asyncSupported=true)
AsyncContext
Is obtained by the ServletRequest methods
startAsync(servletRequest, servletResponse) or startAsync()
Example:
AsyncContext aCtx = req.startAsync(req, res);
Methods to dispatch the request back to the container:
AsyncContext.dispatch(), AsyncContext.dispatch(path), or AsyncContext.dispatch(servletContext, path) Example:
ctx.dispatch("/render.jsp");
AsynchronousListener
http://docs.oracle.com/javaee/6/api/javax/servlet/AsyncListener.html
Methods:
- onComplete(event)
- onError(event)
- onStartAsync(event)
- onTimeOut(event)
Example:
req.addAsyncListener(new AsyncListener() {...
Asynchronous application example in:
OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification
No comments:
Post a Comment