How do I use Ajax to connect to Java servlets?

You need to make an XML Http request to the Servlet for that you need to make a XML Http object in the javascript in your HTML/JSP page var myxmlhttpobj=new GetXmlHttpObject(); function GetXmlHttpObject() { if (window. XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window. ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.

XMLHTTP"); } return null; } Now you need to make a request to the Servlet from the javascript var url="urlofServlet"; var para="parmeter1=value1¶meter2=valu2; myxmlhttpobj. Open("POST",url,true); myxmlhttpobj. SetRequestHeader("Content-type", "application/x-www-form-urlencoded"); myxmlhttpobj.

SetRequestHeader("Content-length", para. Length); myxmlhttpobj. SetRequestHeader("Connection", "close"); myxmlhttpobj.

Onreadystatechange=ajaxComplete; myxmlhttpobj. Send(para); At the server you need to process the result and sent it back as string: PrintWriter out=response.getWriter(); ///Process the input Write the out put out. Println(outputAsString); When the request comes back the myxmlhttpobj.

Onreadystatechange=ajaxComplete; will be called function ajaxComplete(){ if(myxmlhttpobj. ReadyState==4){ ///Display the result on the HTML/JSP Page } } That should help... Also have a look at jQuery Ajax API.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions