bb******@gmail.com wrote:
I've been looking into the possibility of using XMLHTTP for my
enterprise application but I still have a question.
When you send the request to the server, how does the server know how
to handle the request? (i.e. how do I specify what method to call in my
java servlet?)
The request is simply a HTTP request, for instance a GET request, a
servlet then knows how to treat a HTTP GET request and the servlet
container I think provides an API to read the query string. Similar if a
HTTP POST request is send I think a servlet has a method to process such
requests and read out the body of the POST request.
So on the client you need to decide about the URL of the servlet, about
the HTTP request method (e.g. GET, POST etc) and then make the request e.g.
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'servletURL', true);
// now set request header if needed
httpRequest.onreadystatechange = function () {
// handle response here e.g.
if (httpRequest.readyState == 4) {
..
}
};
httpRequest.send(null);
or
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'servletURL', true);
// now set request header if needed
httpRequest.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
httpRequest.onreadystatechange = function () {
// handle response here e.g.
if (httpRequest.readyState == 4) {
..
}
};
httpRequest.send('a=1&b=2');
A HTTP request doesn't call particular methods on the server, for that
you would need to look into webservices, IE/Win with the webservice
behavior and Mozilla with its webservice proxying API allow that but of
course then you also need to implement a web service on the server.
--
Martin Honnen
http://JavaScript.FAQTs.com/