Java Reference
In-Depth Information
The input form requires a unique catalog id to be specified to create a new catalog
entry. The input catalog id in the form is validated against the database content to
see if it is already specified.
Sending an Ajax request
The catalog id data added to the HTML form is sent to the server as the catalog id
is added (not when the form is completed) and an HTTP servlet returns an XML
response that contains information about the validity of the catalog id. In the input.
jsp , the XMLHttpRequest response from the server is processed and if the instructions
indicate that the catalog id is valid, a message "Catalog Id is Valid" is displayed. An
XMLHttpRequest is sent to the server and a response received with each modification
in the input field.
The procedure to send an XMLHttpRequest request and process the XML response
is as follows:
1. Invoke a JavaScript function from an HTML event such as onkeyup.
2. Create an XMLHttpRequest object in the JavaScript function.
3. Open an XMLHttpRequest request, which specifies the servlet URL, the
HTTP method, and whether the request is asynchronous.
4. Register a callback event handler that gets invoked when the request
is complete.
5. Send an XMLHttpRequest request asynchronously.
6. Retrieve the XML response and modify the HTML page.
To initiate an XMLHttpRequest , register a JavaScript function, validateCatalogId() ,
with an event, onkeyup event for example, generated from the HTML form's input
field CatalogId , which is required to be validated:
<form name="validationForm" action="ejb3clientservlet" method="post">
<td>Catalog Id:</td>
<td><input type="text" size="20" id="catalogId"
name="catalogId" onkeyup=validateCatalogId();></td>
<div id="validationMessage"></div>
Search WWH ::

Custom Search