FILE NAME - aja1.jsp
I am using AJAX for sending parameter on the same page using GET Method.
How can I process those parameter in my
JSP code and get back the resuld in responseText Object.
Forexample - In PHP we can echo pramater to access by responseText Object.
My code is given below...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function sendparm(){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var ajaxDisplay = document.getElementById('aj_id');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var nm= document.form1.txt1.value;
var url = "aja1.jsp"
var queryString= "?name=" + nm;
xmlhttp.open("GET",url+queryString,true);
xmlhttp.send(null);
}
</script>
<title>JSP Page</title>
</head>
<body>
<form name="form1" method="get" action="aja2.jsp" value="form1">
<input type="text" value="" name="txt1"></input>
<input type="button" value=click" name="btn1" onclick="sendparm()"></input>
<%
String str = request.getParameter("name");
//////WHAT SHOULD I DO NOW TO PROCESS THIS STR VARIABLE AND TO ACCESS IN AJAX TO INSERT IN HTML
%>
</form>
<div id='aj_id'>Your result will display here</div>
<input type="text" value="" id="asdaasd" name="txt2"></input>
<h1>Hello World!</h1>
</body>
</html>