Java Reference
In-Depth Information
In the JavaScript function validateCatalogId() , create a new XMLHttpRequest
object. If a browser supports the XMLHttpRequest object as an ActiveX object (as in
IE 6), the procedure to create an XMLHttpRequest object is different than when the
XMLHttpRequest object is a window object property (as in IE 7 and Netscape).
<script type="text/javascript">
function validateCatalogId(){
var xmlHttpRequest=init();
function init(){
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
Next, we need to construct the URL to which the XMLHttpRequest will be sent. As
we shall invoke a servlet, EJB3ClientServlet , which is mapped to servlet URL
validateForm as specified in web.xml , specify the URL as ejb3clientservlet?cata
logId=encodeURIComponent(catalogId.value) . The parameter catalogId specifies
the value of CatalogId input in the HTML form. The encodeURIComponent(string)
method is used to encode the CatalogId value. The HTTP method specified is GET ,
which invokes the doGet() method of the servlet. Next, open the XMLHttpRequest
object using the open() method in which specify the HTTP method as GET , the URL
that we constructed, and the asysnchronous boolean as true :
var catalogId = document.getElementById(“catalogId”);«GET»,»ejb3clientservlet?catalogId=»+
encodeURIComponent(catalogId.value), true);
We need to register a callback event handler with the XMLHttpRequest object
using the onreadystatechange property. The callback method is the JavaScript
function processRequest :
We need to send an HTTP request using the send() method. As the HTTP method is
GET , data sent with the send() method is set to null :
Search WWH ::

Custom Search