XMLHTTP Question

B

bboyle18

Hi,

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?)

I'd appreciate any help on this.....I've only got a vaey basic
knowledge of javascript and I am fluent in java.

Thanks,

B
 
M

Martin Honnen

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

Martin Honnen

Mr.Clean wrote:

On the other hand, XMLHTTP CAN call specific "functions", or verbs on
the server. Take, for instance the WebDAV implementation of Hotmail, in
the WebDAV specs, there are no mentions of BPROPPATCH, BDELETE, BMOVE,
verbs, etc. However, you can call them using XMLHTTP on their WebDAV
implementation.

Other protocols can certainly be implemented on top of HTTP or using
HTTP as the transport, for instance a web service client and a web
service server usually communicate by exchanging SOAP messages over HTTP
and for instance the MS web service behavior is implemented with the
help of Microsoft.XMLHTTP.

But the original poster asked about XMLHTTP and servlet communication,
that looks more like doing a certain HTTP request (e.g. GET, POST) on
the client and processing that with the servlet as something that
receives HTTP requests and sends a HTTP response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top