How to get whole Jsp page using AJAX ?

It is so simple just follow below two steps [use netbeans IDE]
————————————————————–
Use Netbeans IDE
—————–

1) Create [ index.jsp ] page as in given image and copy below ajax contents in its script tag
———————————————————————————————

function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject(“Msxml2.XMLHTTP”) // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”) // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != ‘undefined’) {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}

var xmlhttp = new getXMLObject();
function getHomeDotJspPage(){
if(xmlhttp) {
var userName=document.getElementById(“name”).value;
var params = “userName=”+userName;
var url = “home.jsp”
xmlhttp.open(“POST”,url,true);
xmlhttp.onreadystatechange = handleServerResponce;
xmlhttp.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);
xmlhttp.send(params);
}
}

function handleServerResponce() {

if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
var data=xmlhttp.responseText;
document.getElementById(“data”).innerHTML=data;
}
}
}

2) Create home.jsp page same as below image
——————————————-

3) Now Run your Project
———————–
Your comments are heartly invited.

Thank You
———

Advertisements

About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s