> HI...
>
> I am New to Ajax...
Not an issue with a JSP/JSTL forum...
> and now i have a problem how to
> retrive the xmlhttp request in servlet(Control file)
You don't. The XMLHTTP object is a javascript object - it is client side and has nothing to do with Servlets.
On the servlet you work on the HttpServletRequest you get in the doPost or doGet method to get request parameters or headers. If that doesn't make sense to you then you need to buy a book on J2EE.
> and after processing the xmlhttp request and how to
> send the response to the xml...!
Write XML to the HttpServletResponse object.
>
> Plz help..! thanks in advance...!
just call your servlet directly via the JavaScript URL, like:
URL = "/servlets/com.myProject.myServlet?field1=" + document.getElementById('field1').value;
then in your servlet, simple setup would be like:
public void doGet(HttpServletRequest req, HttpServletResponse res) {
try{
PrintWriter out = res.getWriter();
String field1 = req.getParameter("field1");
String result = field1;
// ***** do something with field1
out.print( result );
// or if you are sending xml response then hvae something like this
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
out.println("<?xml version="1.0" encoding="UTF-8" standalone="yes"?>");
out.println("<response><item>"+result"</item></response>");
}catch(Exception e){
logger.debug( e.getMessage() );
logger.debug( e.getStackTrace().toString() );
}finally{;}
}
then, back in your JavaScript (code/file):
function updatePage() {
if (request.readyState == 4)
if (request.status == 200)
{
alert("Server is done!");
var message = request.responseXML.documentElement;
var textvalue = message.getElementsByTagName('item')[0].firstChild.data;
document.getElementById("server").value= textvalue;
}
}